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.
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/rack/cache/entitystore.rb', line 238
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
249
250
251
252
253
254
|
# File 'lib/rack/cache/entitystore.rb', line 249
def exist?(key)
cache.append(key, '')
true
rescue ::Memcached::NotStored
false
end
|
#purge(key) ⇒ Object
269
270
271
272
273
274
|
# File 'lib/rack/cache/entitystore.rb', line 269
def purge(key)
cache.delete(key)
nil
rescue ::Memcached::NotFound
nil
end
|
#read(key) ⇒ Object
256
257
258
259
260
|
# File 'lib/rack/cache/entitystore.rb', line 256
def read(key)
cache.get(key, false)
rescue ::Memcached::NotFound
nil
end
|
#write(body) ⇒ Object
262
263
264
265
266
267
|
# File 'lib/rack/cache/entitystore.rb', line 262
def write(body)
buf = StringIO.new
key, size = slurp(body){|part| buf.write(part) }
cache.set(key, buf.string, 0, false)
[key, size]
end
|