Class: RecordCache::Strategy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/record_cache/strategy/base.rb

Direct Known Subclasses

IdCache, IndexCache, RequestCache

Defined Under Namespace

Modules: Collator

Constant Summary collapse

CLASS_KEY =
:c
ATTRIBUTES_KEY =
:a

Instance Method Summary collapse

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, options)
  @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?

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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)

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/record_cache/strategy/base.rb', line 23

def record_change(record, action)
  raise NotImplementedError
end