Class: CanTango::Ability::Cache::SessionCache
- Defined in:
- lib/cantango/ability/cache/session_cache.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#session ⇒ Object
Returns the value of attribute session.
Attributes inherited from BaseCache
Instance Method Summary collapse
- #cache ⇒ Object
- #cache_key ⇒ Object
-
#initialize(name, options = {}) ⇒ SessionCache
constructor
will be called with :session => session (pointing to user session).
- #invalidate!(key) ⇒ Object
- #load(key) ⇒ Object
- #save(key, rules) ⇒ Object
- #store ⇒ Object
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, = {} 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
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/cantango/ability/cache/session_cache.rb', line 6 def key @key end |
#session ⇒ Object
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
#cache ⇒ Object
40 41 42 |
# File 'lib/cantango/ability/cache/session_cache.rb', line 40 def cache CanTango::Cache::HashCache.instance end |
#cache_key ⇒ Object
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 |
#store ⇒ Object
21 22 23 |
# File 'lib/cantango/ability/cache/session_cache.rb', line 21 def store session[cache_key] end |