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) ⇒ 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
19 20 21 22 23 24 25 |
# File 'lib/cache/object/adapter.rb', line 19 def delete(decorator) DTraceProvider.fire!(:delete, decorator.instance.class.name, decorator.instance.id.to_s) decorator.keys.each do |key| store.delete(key) end end |
#fetch(klass, id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cache/object/adapter.rb', line 27 def fetch(klass, id) DTraceProvider.fire!(:fetch, klass.name, id.to_s, ttl.to_s) store.fetch(KeyGenerator.key_for_object(klass.name, id), expires_in: ttl) do DTraceProvider.fire!(:fetch_miss, klass.name, id.to_s, ttl.to_s) yield end end |
#fetch_mapping(klass, attributes, &block) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/cache/object/adapter.rb', line 36 def fetch_mapping(klass, attributes, &block) DTraceProvider.fire!(:fetch_mapping, klass.name, attributes.inspect, ttl.to_s) store.fetch(KeyGenerator.key_for_mapping(klass.name, attributes), expires_in: ttl) do DTraceProvider.fire!(:fetch_mapping_miss, klass.name, attributes.inspect, ttl.to_s) yield end end |
#read_multi(args) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/cache/object/adapter.rb', line 45 def read_multi(args) total = args.size result = store.read_multi(*args) found = result.size DTraceProvider.fire!(:read_multi, args.inspect, found, total - found) result end |
#write(decorator) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/cache/object/adapter.rb', line 11 def write(decorator) DTraceProvider.fire!(:write, decorator.instance.class.name, decorator.instance.id.to_s, ttl.to_s) decorator.keys.each do |key| store.write(key, decorator.instance, expires_in: ttl) end end |