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 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

[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

[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

[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

[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

[Validate]