Sha256: 4ce11eec4ee806750c7d8554ec6b31ba3a328287810dfa40710fcb3a2b2d6323
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
class Memcache class LocalServer < Base def initialize @data = {} @expiry = {} end def name "local:#{hash}" end def stats { # curr_items may include items that have expired. 'curr_items' => @data.size, 'expiry_count' => @expiry.size, } end def flush_all(delay = 0) raise 'flush_all not supported with delay' if delay != 0 @data.clear @expiry.clear end def get(keys, cas = false) if keys.kind_of?(Array) hash = {} keys.each do |key| key = key.to_s result = get(key) hash[key] = result if result end hash else key = cache_key(keys) if @expiry[key] and Time.now > @expiry[key] @data[key] = nil @expiry[key] = nil end @data[key] end end def set(key, value, expiry = 0, flags = 0) key = cache_key(key) @data[key] = {:value => value.to_s, :flags => flags} expiry = Time.at(expiry) if expiry > 60*60*24*30 if expiry.kind_of?(Time) @expiry[key] = expiry else expiry = expiry.to_i @expiry[key] = expiry == 0 ? nil : Time.now + expiry end value end def delete(key) @data.delete(cache_key(key)) && true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
memcache-1.4.0 | lib/memcache/local_server.rb |