Module: Bizside::CacheUtil

Included in:
CacheUtils
Defined in:
lib/bizside/cache_util.rb

Instance Method Summary collapse

Instance Method Details

#cacheObject



32
33
34
# File 'lib/bizside/cache_util.rb', line 32

def cache
  raise 'サブクラスで実装'
end

#clear(options = nil) ⇒ Object



27
28
29
30
# File 'lib/bizside/cache_util.rb', line 27

def clear(options = nil)
  output_log "CLEAR ALL CACHE"
  cache.clear(options)
end

#delete(key) ⇒ Object



17
18
19
20
# File 'lib/bizside/cache_util.rb', line 17

def delete(key)
  output_log "CLEAR CACHE: #{key}"
  cache.delete(key)
end

#delete_matched(matcher) ⇒ Object



22
23
24
25
# File 'lib/bizside/cache_util.rb', line 22

def delete_matched(matcher)
  output_log "CLEAR CACHE: #{matcher}"
  cache.delete_matched(matcher)
end

#fetch(key, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bizside/cache_util.rb', line 4

def fetch(key, options = {})
  if block_given?
    action = cache.exist?(key) ? 'READ' : 'WRITE'
    output_log "#{action} CACHE: #{key}"
    cache.fetch(key, options) do
      yield
    end
  else
    output_log "READ CACHE: #{key}" 
    cache.fetch(key, options)
  end
end