Class: Perry::Middlewares::CacheRecords

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/perry/middlewares/cache_records.rb,
lib/perry/middlewares/cache_records.rb,
lib/perry/middlewares/cache_records/entry.rb,
lib/perry/middlewares/cache_records/store.rb

Defined Under Namespace

Modules: Scopes Classes: Entry, Store

Constant Summary collapse

DEFAULT_LONGEVITY =

TRP: Default to a 5 minute cache

5*60

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

included

Constructor Details

#initialize(adapter, config = {}) ⇒ CacheRecords

Returns a new instance of CacheRecords.



31
32
33
34
# File 'lib/perry/middlewares/cache_records.rb', line 31

def initialize(adapter, config={})
  @adapter = adapter
  self.record_count_threshold = config[:record_count_threshold]
end

Instance Attribute Details

#record_count_thresholdObject

Returns the value of attribute record_count_threshold.



10
11
12
# File 'lib/perry/middlewares/cache_records.rb', line 10

def record_count_threshold
  @record_count_threshold
end

Class Method Details

.global_cacheObject



15
16
17
# File 'lib/perry/middlewares/cache_records.rb', line 15

def self.global_cache
  @@global_cache ||= {}
end

.reset_global_cacheObject



19
20
21
# File 'lib/perry/middlewares/cache_records.rb', line 19

def self.reset_global_cache
  @@global_cache = {}
end

Instance Method Details

#cache_storeObject



27
28
29
# File 'lib/perry/middlewares/cache_records.rb', line 27

def cache_store
  self.class.global_cache[self] || reset_cache_store
end

#call(options) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/perry/middlewares/cache_records.rb', line 36

def call(options)
  if options[:relation] && Perry::Caching.enabled?
    call_with_cache(options)
  else
    @adapter.call(options)
  end
end

#reset_cache_store(default_longevity = DEFAULT_LONGEVITY) ⇒ Object



23
24
25
# File 'lib/perry/middlewares/cache_records.rb', line 23

def reset_cache_store(default_longevity=DEFAULT_LONGEVITY)
  self.class.global_cache[self] = Perry::Middlewares::CacheRecords::Store.new(default_longevity)
end