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.
210
211
212
213
214
215
216
217
218
|
# File 'lib/rack/cache/entitystore.rb', line 210
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
220
221
222
|
# File 'lib/rack/cache/entitystore.rb', line 220
def exist?(key)
!cache.get(key).nil?
end
|
#purge(key) ⇒ Object
234
235
236
237
|
# File 'lib/rack/cache/entitystore.rb', line 234
def purge(key)
cache.delete(key)
nil
end
|
#read(key) ⇒ Object
224
225
226
|
# File 'lib/rack/cache/entitystore.rb', line 224
def read(key)
cache.get(key)
end
|
#write(body) ⇒ Object
228
229
230
231
232
|
# File 'lib/rack/cache/entitystore.rb', line 228
def write(body)
buf = StringIO.new
key, size = slurp(body){|part| buf.write(part) }
[key, size] if cache.set(key, buf.string)
end
|