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)



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

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[cache_key] = @cache
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#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



40
41
42
# File 'lib/cantango/ability/cache/session_cache.rb', line 40

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

#cache_keyObject



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

def cache_key
  @cache_key ||= :rules_cache
end

#invalidate!(key) ⇒ Object



35
36
37
38
# File 'lib/cantango/ability/cache/session_cache.rb', line 35

def invalidate! key
  raise "no key" if key.nil?
  store.delete(key)
end

#load(key) ⇒ Object



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

def load key
  raise "no key" if key.nil?
  store.load! key
end

#save(key, rules) ⇒ Object



30
31
32
33
# File 'lib/cantango/ability/cache/session_cache.rb', line 30

def save key, rules
  raise "no key" if key.nil?
  store.save!(key, rules)
end

#storeObject



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

def store
  session[cache_key]
end