class Tml::CacheAdapters::Rails
Public Class Methods
new()
click to toggle source
# File lib/tml/cache_adapters/rails.rb, line 35 def initialize @cache = Rails.cache end
Public Instance Methods
cache_name()
click to toggle source
# File lib/tml/cache_adapters/rails.rb, line 39 def cache_name @cache.class.name end
clear(opts = {})
click to toggle source
# File lib/tml/cache_adapters/rails.rb, line 92 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/tml/cache_adapters/rails.rb, line 75 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/tml/cache_adapters/rails.rb, line 84 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/tml/cache_adapters/rails.rb, line 47 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/tml/cache_adapters/rails.rb, line 43 def read_only? false end
store(key, data, opts = {})
click to toggle source
# File lib/tml/cache_adapters/rails.rb, line 66 def store(key, data, opts = {}) info("Cache store: #{key}") @cache.write(versioned_key(key, opts), strip_extensions(data)) data rescue Exception => ex warn("Failed to store data: #{ex.message}") key end