Class Rack::Cache::EntityStore::MemCached
In: lib/rack/cache/entitystore.rb
Parent: MemCacheBase

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

exist?   new   purge   read   write  

Public Class methods

[Source]

     # File lib/rack/cache/entitystore.rb, line 246
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

[Source]

     # File lib/rack/cache/entitystore.rb, line 257
257:       def exist?(key)
258:         cache.append(key, '')
259:         true
260:       rescue ::Memcached::NotStored
261:         false
262:       end

[Source]

     # File lib/rack/cache/entitystore.rb, line 277
277:       def purge(key)
278:         cache.delete(key)
279:         nil
280:       rescue ::Memcached::NotFound
281:         nil
282:       end

[Source]

     # File lib/rack/cache/entitystore.rb, line 264
264:       def read(key)
265:         cache.get(key, false)
266:       rescue ::Memcached::NotFound
267:         nil
268:       end

[Source]

     # File lib/rack/cache/entitystore.rb, line 270
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

[Validate]