Class: Rack::Cache::EntityStore::MemCache
Overview
Uses the memcache-client ruby library. This is the default 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 = {}) ⇒ MemCache
Returns a new instance of MemCache.
204
205
206
207
208
209
210
211
212
|
# File 'lib/rack/cache/entitystore.rb', line 204
def initialize(server="localhost:11211", options={})
@cache =
if server.respond_to?(:stats)
server
else
require 'memcache'
::MemCache.new(server, options)
end
end
|
Instance Method Details
#exist?(key) ⇒ Boolean
214
215
216
|
# File 'lib/rack/cache/entitystore.rb', line 214
def exist?(key)
!cache.get(key).nil?
end
|
#purge(key) ⇒ Object
228
229
230
231
|
# File 'lib/rack/cache/entitystore.rb', line 228
def purge(key)
cache.delete(key)
nil
end
|
#read(key) ⇒ Object
218
219
220
|
# File 'lib/rack/cache/entitystore.rb', line 218
def read(key)
cache.get(key)
end
|
#write(body) ⇒ Object
222
223
224
225
226
|
# File 'lib/rack/cache/entitystore.rb', line 222
def write(body)
buf = StringIO.new
key, size = slurp(body){|part| buf.write(part) }
[key, size] if cache.set(key, buf.string)
end
|