class Gateway::Memcache
Public Instance Methods
default_expiration()
click to toggle source
# File lib/gateway/memcache.rb, line 25 def default_expiration options.fetch :expiration, 0 end
get(id, raw = false)
click to toggle source
# File lib/gateway/memcache.rb, line 9 def get(id, raw = false) opts = {:retry => false} execute(:get, id, opts) do |conn| conn.get(id, raw) end end
set(id, value, expiration=nil, raw = false)
click to toggle source
# File lib/gateway/memcache.rb, line 16 def set(id, value, expiration=nil, raw = false) opts = {:retry => false} ttl = expiration || default_expiration execute(:set, id, opts) do |conn| conn.set(id, value, ttl, raw) end end
Protected Instance Methods
connect()
click to toggle source
# File lib/gateway/memcache.rb, line 31 def connect client = MemCache.new( :timeout => options[:socket_timeout], :multithread => false, # thread safty managed by gateway ) client.servers = options[:servers] client end
disconnect(conn)
click to toggle source
# File lib/gateway/memcache.rb, line 40 def disconnect(conn) # let memcache client control when to retry # external control only making things worse #conn.close end
reconnect(conn)
click to toggle source
# File lib/gateway/memcache.rb, line 46 def reconnect(conn) # let memcache client control when to retry # external control only making things worse #conn.reset end
success_message(resp)
click to toggle source
# File lib/gateway/memcache.rb, line 56 def success_message(resp) resp ? 'HIT' : 'MISS' end
success_status(resp)
click to toggle source
# File lib/gateway/memcache.rb, line 52 def success_status(resp) resp ? 200 : 404 end