Class: RecordCache::Strategy::Base
- Inherits:
-
Object
- Object
- RecordCache::Strategy::Base
- Defined in:
- lib/record_cache/strategy/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#cacheable?(query) ⇒ Boolean
Can the cache retrieve the records based on this query?.
-
#fetch(query) ⇒ Object
Fetch all records and sort and filter locally.
-
#initialize(base, strategy_id, record_store, options) ⇒ Base
constructor
A new instance of Base.
-
#invalidate(id) ⇒ Object
Handle invalidation call.
-
#record_change(record, action) ⇒ Object
Handle create/update/destroy (use record.previous_changes to find the old values in case of an update).
Constructor Details
#initialize(base, strategy_id, record_store, options) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 |
# File 'lib/record_cache/strategy/base.rb', line 5 def initialize(base, strategy_id, record_store, ) @base = base @strategy_id = strategy_id @record_store = record_store @cache_key_prefix = "rc/#{options[:key] || @base.name}/".freeze end |
Instance Method Details
#cacheable?(query) ⇒ Boolean
Can the cache retrieve the records based on this query?
26 27 28 |
# File 'lib/record_cache/strategy/base.rb', line 26 def cacheable?(query) raise NotImplementedError end |
#fetch(query) ⇒ Object
Fetch all records and sort and filter locally
13 14 15 16 17 18 |
# File 'lib/record_cache/strategy/base.rb', line 13 def fetch(query) records = fetch_records(query) Util.filter!(records, query.wheres) if query.wheres.size > 0 Util.sort!(records, query.sort_orders) if query.sorted? records end |
#invalidate(id) ⇒ Object
Handle invalidation call
31 32 33 |
# File 'lib/record_cache/strategy/base.rb', line 31 def invalidate(id) raise NotImplementedError end |
#record_change(record, action) ⇒ Object
Handle create/update/destroy (use record.previous_changes to find the old values in case of an update)
21 22 23 |
# File 'lib/record_cache/strategy/base.rb', line 21 def record_change(record, action) raise NotImplementedError end |