Class Rack::Cache::EntityStore::MemCached

  1. lib/rack/cache/entitystore.rb

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.

Methods

public class

  1. new

public instance

  1. exist?
  2. purge
  3. read
  4. write

Public class methods

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

Public instance methods

exist? (key)
[show source]
     # File lib/rack/cache/entitystore.rb, line 255
255:       def exist?(key)
256:         cache.append(key, '')
257:         true
258:       rescue ::Memcached::NotStored
259:         false
260:       end
purge (key)
[show source]
     # File lib/rack/cache/entitystore.rb, line 275
275:       def purge(key)
276:         cache.delete(key)
277:         nil
278:       rescue ::Memcached::NotFound
279:         nil
280:       end
read (key)
[show source]
     # File lib/rack/cache/entitystore.rb, line 262
262:       def read(key)
263:         cache.get(key, false)
264:       rescue ::Memcached::NotFound
265:         nil
266:       end
write (body)
[show source]
     # File lib/rack/cache/entitystore.rb, line 268
268:       def write(body)
269:         buf = StringIO.new
270:         key, size = slurp(body){|part| buf.write(part) }
271:         cache.set(key, buf.string, 0, false)
272:         [key, size]
273:       end