lib/cache/object/adapter.rb in cache-object-0.0.4 vs lib/cache/object/adapter.rb in cache-object-0.0.5

- old
+ new

@@ -7,34 +7,49 @@ raise "Cache Store is nil, please initialize" unless store @store = store end 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 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 - def fetch(klass, id, &block) - store.fetch(KeyGenerator.key_for_object(klass.name, id), - expires_in: ttl, - &block) + 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 def fetch_mapping(klass, attributes, &block) - store.fetch(KeyGenerator.key_for_mapping(klass.name, attributes), - expires_in: ttl, - &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 def read_multi(args) - store.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 private def ttl