Class: RecordCache::Strategy::Base

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

Direct Known Subclasses

IdCache, IndexCache, RequestCache

Instance Method Summary collapse

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, 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)


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

Raises:

  • (NotImplementedError)


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)

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/record_cache/strategy/base.rb', line 21

def record_change(record, action)
  raise NotImplementedError
end