class Tml::CacheAdapters::Memcache
Public Class Methods
new()
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 37 def initialize config = Tml.config.cache options = { :namespace => config[:namespace] || 'tml', :compress => config[:compress].nil? ? true : config[:compress] } @cache = Dalli::Client.new(config[:host], options) end
Public Instance Methods
cache_name()
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 43 def cache_name 'memcache' end
clear(opts = {})
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 100 def clear(opts = {}) info("Cache clear") rescue Exception => ex warn("Failed to clear cache: #{key}") end
delete(key, opts = {})
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 83 def delete(key, opts = {}) info("Cache delete: #{key}") @cache.delete(versioned_key(key, opts)) key rescue Exception => ex warn("Failed to delete data: #{key}") key end
exist?(key, opts = {})
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 92 def exist?(key, opts = {}) data = @cache.get(versioned_key(key, opts)) not data.nil? rescue Exception => ex warn("Failed to check if key exists: #{key}") false end
fetch(key, opts = {}) { || ... }
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 51 def fetch(key, opts = {}) data = @cache.get(versioned_key(key, opts)) if data info("Cache hit: #{key}") return data end info("Cache miss: #{key}") return nil unless block_given? data = yield store(key, data) data rescue Exception => ex warn("#{ex.message}: #{key}") return nil unless block_given? yield end
read_only?()
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 47 def read_only? false end
store(key, data, opts = {})
click to toggle source
# File lib/tml/cache_adapters/memcache.rb, line 73 def store(key, data, opts = {}) info("Cache store: #{key}") ttl = opts[:ttl] || Tml.config.cache[:timeout] || 0 @cache.set(versioned_key(key, opts), strip_extensions(data), ttl) data rescue Exception => ex warn("Failed to store data: #{key}") data end