class Rack::Cache::EntityStore::MemCached

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.

Public Class Methods

new(server="localhost:11211", options={}) click to toggle source
    # File lib/rack/cache/entity_store.rb
246 def initialize(server="localhost:11211", options={})
247   options[:prefix_key] ||= options.delete(:namespace) if options.key?(:namespace)
248   @cache =
249     if server.respond_to?(:stats)
250       server
251     else
252       require 'memcached'
253       ::Memcached.new(server, options)
254     end
255 end

Public Instance Methods

exist?(key) click to toggle source
    # File lib/rack/cache/entity_store.rb
257 def exist?(key)
258   cache.append(key, '')
259   true
260 rescue ::Memcached::NotStored
261   false
262 end
purge(key) click to toggle source
    # File lib/rack/cache/entity_store.rb
277 def purge(key)
278   cache.delete(key)
279   nil
280 rescue ::Memcached::NotFound
281   nil
282 end
read(key) click to toggle source
    # File lib/rack/cache/entity_store.rb
264 def read(key)
265   cache.get(key, false)
266 rescue ::Memcached::NotFound
267   nil
268 end
write(body, ttl=0) click to toggle source
    # File lib/rack/cache/entity_store.rb
270 def write(body, ttl=0)
271   buf = StringIO.new
272   key, size = slurp(body){|part| buf.write(part) }
273   cache.set(key, buf.string, ttl, false)
274   [key, size]
275 end