Class: RecordCache::Strategy::Base
- Inherits:
-
Object
- Object
- RecordCache::Strategy::Base
- Defined in:
- lib/record_cache/strategy/base.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Collator
Constant Summary collapse
- CLASS_KEY =
:c
- ATTRIBUTES_KEY =
:a
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.
7 8 9 10 11 12 |
# File 'lib/record_cache/strategy/base.rb', line 7 def initialize(base, strategy_id, record_store, ) @base = base @strategy_id = strategy_id @record_store = record_store @cache_key_prefix = "rc/#{[:key] || @base.name}/".freeze end |
Instance Method Details
#cacheable?(query) ⇒ Boolean
Can the cache retrieve the records based on this query?
28 29 30 |
# File 'lib/record_cache/strategy/base.rb', line 28 def cacheable?(query) raise NotImplementedError end |
#fetch(query) ⇒ Object
Fetch all records and sort and filter locally
15 16 17 18 19 20 |
# File 'lib/record_cache/strategy/base.rb', line 15 def fetch(query) records = fetch_records(query) filter!(records, query.wheres) if query.wheres.size > 0 sort!(records, query.sort_orders) if query.sorted? records end |
#invalidate(id) ⇒ Object
Handle invalidation call
33 34 35 |
# File 'lib/record_cache/strategy/base.rb', line 33 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)
23 24 25 |
# File 'lib/record_cache/strategy/base.rb', line 23 def record_change(record, action) raise NotImplementedError end |