class Tr8n::CacheAdapters::Rails
Public Class Methods
new()
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 35 def initialize Tr8n.logger.info('Initializing Rails cache...') @cache = Rails.cache end
Public Instance Methods
cache_name()
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 40 def cache_name @cache.class.name end
clear(opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 93 def clear(opts = {}) info("Cache clear") rescue Exception => ex warn("Failed to clear cache: #{ex.message}") end
delete(key, opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 76 def delete(key, opts = {}) info("Cache delete: #{key}") @cache.delete(versioned_key(key, opts)) key rescue Exception => ex warn("Failed to delete data: #{ex.message}") key end
exist?(key, opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 85 def exist?(key, opts = {}) data = @cache.fetch(versioned_key(key, opts)) not data.nil? rescue Exception => ex warn("Failed to check if key exists: #{ex.message}") false end
fetch(key, opts = {}) { || ... }
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 48 def fetch(key, opts = {}) miss = false data = @cache.fetch(versioned_key(key, opts)) do info("Cache miss: #{key}") miss = true if block_given? yield else nil end end info("Cache hit: #{key}") unless miss data rescue Exception => ex warn("Failed to retrieve data: #{ex.message}") return nil unless block_given? yield end
read_only?()
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 44 def read_only? false end
store(key, data, opts = {})
click to toggle source
# File lib/tr8n/cache_adapters/rails.rb, line 67 def store(key, data, opts = {}) info("Cache store: #{key}") @cache.write(versioned_key(key, opts), data) data rescue Exception => ex warn("Failed to store data: #{ex.message}") key end