Uses the Dalli ruby library. This is the default unless the memcached library has already been required.
# File lib/rack/cache/entitystore.rb, line 210 def initialize(server="localhost:11211", options={}) @cache = if server.respond_to?(:stats) server else require 'dalli' ::Dalli::Client.new(server, options) end end
# File lib/rack/cache/entitystore.rb, line 220 def exist?(key) !cache.get(key).nil? end
# File lib/rack/cache/entitystore.rb, line 236 def purge(key) cache.delete(key) nil end
# File lib/rack/cache/entitystore.rb, line 224 def read(key) data = cache.get(key) data.force_encoding('BINARY') if data.respond_to?(:force_encoding) data end
# File lib/rack/cache/entitystore.rb, line 230 def write(body, ttl=nil) buf = StringIO.new key, size = slurp(body){|part| buf.write(part) } [key, size] if cache.set(key, buf.string, ttl) end