class McCache
Public Class Methods
cache_exists?()
click to toggle source
# File lib/caches/mc_cache.rb, line 20 def cache_exists? # @@client.read('test') # rescue Exception => error # @@client = nil Net::HTTP.get(URI("http://#{@@config['host']}")) rescue Errno::ECONNREFUSED => error puts "**** Error: #{error.message}" @@client = nil rescue Net::HTTPBadResponse => error # do nothing end
client()
click to toggle source
# File lib/caches/mc_cache.rb, line 7 def client @@client end
delete(key, options = {})
click to toggle source
# File lib/caches/mc_cache.rb, line 44 def delete(key, options = {}) return unless client deleted = read(key) client.delete(key) deleted end
initialize()
click to toggle source
# File lib/caches/mc_cache.rb, line 11 def initialize @@config ||= ConfigService.load_config('memcached.yml')[ConfigService.environment] @@client ||= Dalli::Client.new(@@config['host'], { namespace: @@config.namespace, compress: @@config.compress}) cache_exists? rescue Exception => error puts("McCache.initialize error: #{error.message}") @@client = nil end
read(key, options = {})
click to toggle source
Cache API, mimics ActiveSupport::Cache::Store api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html
# File lib/caches/mc_cache.rb, line 34 def read(key, options = {}) return unless client client.get(key, options) end
write(key, value, options = {})
click to toggle source
# File lib/caches/mc_cache.rb, line 39 def write(key, value, options = {}) return unless client client.set(key, value, options[:expires_in], options) end