Class: Cache::Object::Adapter
- Inherits:
-
Object
- Object
- Cache::Object::Adapter
- Defined in:
- lib/cache/object/adapter.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #delete(decorator) ⇒ Object
- #fetch(klass, id, &block) ⇒ Object
- #fetch_mapping(klass, attributes, &block) ⇒ Object
-
#initialize(store) ⇒ Adapter
constructor
A new instance of Adapter.
- #read_multi(args) ⇒ Object
- #write(decorator) ⇒ Object
Constructor Details
#initialize(store) ⇒ Adapter
Returns a new instance of Adapter.
6 7 8 9 |
# File 'lib/cache/object/adapter.rb', line 6 def initialize(store) raise "Cache Store is nil, please initialize" unless store @store = store end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/cache/object/adapter.rb', line 4 def store @store end |
Instance Method Details
#delete(decorator) ⇒ Object
17 18 19 20 21 |
# File 'lib/cache/object/adapter.rb', line 17 def delete(decorator) decorator.keys.each do |key| store.delete(key) end end |
#fetch(klass, id, &block) ⇒ Object
23 24 25 26 27 |
# File 'lib/cache/object/adapter.rb', line 23 def fetch(klass, id, &block) store.fetch(KeyGenerator.key_for_object(klass.name, id), expires_in: ttl, &block) end |
#fetch_mapping(klass, attributes, &block) ⇒ Object
29 30 31 32 33 |
# File 'lib/cache/object/adapter.rb', line 29 def fetch_mapping(klass, attributes, &block) store.fetch(KeyGenerator.key_for_mapping(klass.name, attributes), expires_in: ttl, &block) end |
#read_multi(args) ⇒ Object
35 36 37 |
# File 'lib/cache/object/adapter.rb', line 35 def read_multi(args) store.read_multi(*args) end |
#write(decorator) ⇒ Object
11 12 13 14 15 |
# File 'lib/cache/object/adapter.rb', line 11 def write(decorator) decorator.keys.each do |key| store.write(key, decorator.instance, expires_in: ttl) end end |