Class: Rack::Cache::EntityStore::Dalli
Overview
Uses the Dalli ruby library. This is the default unless the memcached library has already been required.
Constant Summary
DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED, NOOP
Instance Attribute Summary
Attributes inherited from MemCacheBase
#cache
Instance Method Summary
collapse
#open, resolve
Constructor Details
#initialize(server = "localhost:11211", options = {}) ⇒ Dalli
Returns a new instance of Dalli.
210
211
212
213
214
215
216
217
218
|
# File 'lib/rack/cache/entity_store.rb', line 210
def initialize(server="localhost:11211", options={})
@cache =
if server.respond_to?(:stats)
server
else
require 'dalli'
::Dalli::Client.new(server, options)
end
end
|
Instance Method Details
#exist?(key) ⇒ Boolean
220
221
222
|
# File 'lib/rack/cache/entity_store.rb', line 220
def exist?(key)
!cache.get(key).nil?
end
|
#purge(key) ⇒ Object
236
237
238
239
|
# File 'lib/rack/cache/entity_store.rb', line 236
def purge(key)
cache.delete(key)
nil
end
|
#read(key) ⇒ Object
224
225
226
227
228
|
# File 'lib/rack/cache/entity_store.rb', line 224
def read(key)
data = cache.get(key)
data.force_encoding('BINARY') if data.respond_to?(:force_encoding)
data
end
|
#write(body, ttl = nil) ⇒ Object
230
231
232
233
234
|
# File 'lib/rack/cache/entity_store.rb', line 230
def write(body, ttl=nil)
buf = StringIO.new
key, size = slurp(body){|part| buf.write(part) }
[key, size] if cache.set(key, buf.string, ttl)
end
|