Class: CanTango::Ability::Cache::SessionCache

Inherits:
BaseCache
  • Object
show all
Defined in:
lib/cantango/ability/cache/session_cache.rb

Instance Attribute Summary collapse

Attributes inherited from BaseCache

#name, #options

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ SessionCache

will be called with :session => session (pointing to user session)



8
9
10
11
12
13
14
# File 'lib/cantango/ability/cache/session_cache.rb', line 8

def initialize name, options = {}
  super # will set all instance vars using options hash
  @cache = cache
  @cache.configure_with :type => :memory
  raise "SessionCache must be initialized with a :session option" if !session
  session[:rules_cache] = @cache
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



5
6
7
# File 'lib/cantango/ability/cache/session_cache.rb', line 5

def session
  @session
end

Instance Method Details

#cacheObject



32
33
34
35
# File 'lib/cantango/ability/cache/session_cache.rb', line 32

def cache
  CanTango::Cache::HashCache.instance
  # CanTango::Cache::MonetaCache.instance
end

#invalidate!(key) ⇒ Object



28
29
30
# File 'lib/cantango/ability/cache/session_cache.rb', line 28

def invalidate! key
  store.delete key
end

#load(key) ⇒ Object



20
21
22
# File 'lib/cantango/ability/cache/session_cache.rb', line 20

def load key
  store.load! key
end

#save(key, rules) ⇒ Object



24
25
26
# File 'lib/cantango/ability/cache/session_cache.rb', line 24

def save key, rules
  store.save! key, rules
end

#storeObject



16
17
18
# File 'lib/cantango/ability/cache/session_cache.rb', line 16

def store
  session[:rules_cache]
end