Class: RecordCache::Strategy::IdCache
- Defined in:
- lib/record_cache/strategy/id_cache.rb
Instance Method Summary collapse
-
#cacheable?(query) ⇒ Boolean
Can the cache retrieve the records based on this query?.
-
#invalidate(id) ⇒ Object
Handle invalidation call.
-
#record_change(record, action) ⇒ Object
Update the version store and the record store.
Methods inherited from Base
Constructor Details
This class inherits a constructor from RecordCache::Strategy::Base
Instance Method Details
#cacheable?(query) ⇒ Boolean
Can the cache retrieve the records based on this query?
6 7 8 9 |
# File 'lib/record_cache/strategy/id_cache.rb', line 6 def cacheable?(query) ids = query.where_ids(:id) ids && (query.limit.nil? || (query.limit == 1 && ids.size == 1)) end |
#invalidate(id) ⇒ Object
Handle invalidation call
24 25 26 |
# File 'lib/record_cache/strategy/id_cache.rb', line 24 def invalidate(id) version_store.delete(cache_key(id)) end |
#record_change(record, action) ⇒ Object
Update the version store and the record store
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/record_cache/strategy/id_cache.rb', line 12 def record_change(record, action) key = cache_key(record.id) if action == :destroy version_store.delete(key) else # update the version store and add the record to the cache new_version = version_store.increment(key) record_store.write(versioned_key(key, new_version), Util.serialize(record)) end end |