Uses the memcached client library. The ruby based memcache-client is used in preference to this store unless the memcached library has already been required.
# File lib/rack/cache/entitystore.rb, line 246 def initialize(server="localhost:11211", options={}) options[:prefix_key] ||= options.delete(:namespace) if options.key?(:namespace) @cache = if server.respond_to?(:stats) server else require 'memcached' ::Memcached.new(server, options) end end
# File lib/rack/cache/entitystore.rb, line 257 def exist?(key) cache.append(key, '') true rescue ::Memcached::NotStored false end
# File lib/rack/cache/entitystore.rb, line 277 def purge(key) cache.delete(key) nil rescue ::Memcached::NotFound nil end
# File lib/rack/cache/entitystore.rb, line 264 def read(key) cache.get(key, false) rescue ::Memcached::NotFound nil end
# File lib/rack/cache/entitystore.rb, line 270 def write(body, ttl=0) buf = StringIO.new key, size = slurp(body){|part| buf.write(part) } cache.set(key, buf.string, ttl, false) [key, size] end