Class: Rack::Cache::EntityStore::MemCached
Overview
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.
Constant Summary
DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED
Instance Attribute Summary
Attributes inherited from MemCacheBase
#cache
Instance Method Summary
collapse
#open, resolve
Constructor Details
#initialize(server = "localhost:11211", options = {}) ⇒ MemCached
Returns a new instance of MemCached.
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/rack/cache/entitystore.rb', line 244
def initialize(server="localhost:11211", options={})
options[:prefix_key] ||= options.delete(:namespace) if options.key?(:namespace)
@cache =
if server.respond_to?(:stats)
server
else
require 'memcached'
::Memcached.new(server, options)
end
end
|
Instance Method Details
#exist?(key) ⇒ Boolean
255
256
257
258
259
260
|
# File 'lib/rack/cache/entitystore.rb', line 255
def exist?(key)
cache.append(key, '')
true
rescue ::Memcached::NotStored
false
end
|
#purge(key) ⇒ Object
275
276
277
278
279
280
|
# File 'lib/rack/cache/entitystore.rb', line 275
def purge(key)
cache.delete(key)
nil
rescue ::Memcached::NotFound
nil
end
|
#read(key) ⇒ Object
262
263
264
265
266
|
# File 'lib/rack/cache/entitystore.rb', line 262
def read(key)
cache.get(key, false)
rescue ::Memcached::NotFound
nil
end
|
#write(body) ⇒ Object
268
269
270
271
272
273
|
# File 'lib/rack/cache/entitystore.rb', line 268
def write(body)
buf = StringIO.new
key, size = slurp(body){|part| buf.write(part) }
cache.set(key, buf.string, 0, false)
[key, size]
end
|