Module: Card::ViewCache

Defined in:
lib/card/view_cache.rb

Constant Summary collapse

SIZE =
500
LIMIT =

reduce cache size to SIZE if LIMIT is reached

1000
CNT_KEY =
'view_cache_cnt'.freeze
FREQUENCY_KEY =
'view_cache_frequency'.freeze

Class Method Summary collapse

Class Method Details

.cacheObject



9
10
11
# File 'lib/card/view_cache.rb', line 9

def cache
  Card::Cache[Card::ViewCache]
end

.fetch(format, view, args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/card/view_cache.rb', line 13

def fetch format, view, args, &block
  return yield if cacheable_view?(view, format)

  key = cache_key view, format, args
  unless cache.exist?(key)
    increment_cached_views_cnt
    reduce_cache if cached_views_cnt > LIMIT
  end
  increment_frequency key

  if Card.config.view_cache == 'debug'
    verbose_fetch key, &bloack
  else
    cache.fetch key, &block
  end
end

.resetObject



30
31
32
# File 'lib/card/view_cache.rb', line 30

def reset
  cache.reset
end