module Bizside::CacheUtil

Public Instance Methods

cache() click to toggle source
# File lib/bizside/cache_util.rb, line 32
def cache
  raise 'サブクラスで実装'
end
clear(options = nil) click to toggle source
# File lib/bizside/cache_util.rb, line 27
def clear(options = nil)
  output_log "CLEAR ALL CACHE"
  cache.clear(options)
end
delete(key) click to toggle source
# File lib/bizside/cache_util.rb, line 17
def delete(key)
  output_log "CLEAR CACHE: #{key}"
  cache.delete(key)
end
delete_matched(matcher) click to toggle source
# 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 = {}) { || ... } click to toggle source
# 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

Private Instance Methods

output_log(message) click to toggle source
# File lib/bizside/cache_util.rb, line 38
def output_log message
  if defined?(Rails) && Rails.logger
    Rails.logger.info message
  else
    puts message
  end
end