Class: Rack::Cache::MetaStore::Dalli
- Inherits:
-
MemCacheBase
- Object
- Rack::Cache::MetaStore
- MemCacheBase
- Rack::Cache::MetaStore::Dalli
- Defined in:
- lib/rack/cache/meta_store.rb
Constant Summary
Constants inherited from Rack::Cache::MetaStore
DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED
Instance Attribute Summary
Attributes inherited from MemCacheBase
Instance Method Summary collapse
-
#initialize(server = "localhost:11211", options = {}) ⇒ Dalli
constructor
A new instance of Dalli.
- #purge(key) ⇒ Object
- #read(key) ⇒ Object
-
#write(key, entries, ttl = 0) ⇒ Object
Default TTL to zero, interpreted as “don’t expire” by Memcached.
Methods inherited from MemCacheBase
Methods inherited from Rack::Cache::MetaStore
#cache_key, #invalidate, #lookup, #store
Constructor Details
#initialize(server = "localhost:11211", options = {}) ⇒ Dalli
Returns a new instance of Dalli.
327 328 329 330 331 332 333 334 335 |
# File 'lib/rack/cache/meta_store.rb', line 327 def initialize(server="localhost:11211", ={}) @cache = if server.respond_to?(:stats) server else require 'dalli' ::Dalli::Client.new(server, ) end end |
Instance Method Details
#purge(key) ⇒ Object
348 349 350 351 |
# File 'lib/rack/cache/meta_store.rb', line 348 def purge(key) cache.delete(hexdigest(key)) nil end |
#read(key) ⇒ Object
337 338 339 340 |
# File 'lib/rack/cache/meta_store.rb', line 337 def read(key) key = hexdigest(key) cache.get(key) || [] end |
#write(key, entries, ttl = 0) ⇒ Object
Default TTL to zero, interpreted as “don’t expire” by Memcached.
343 344 345 346 |
# File 'lib/rack/cache/meta_store.rb', line 343 def write(key, entries, ttl = 0) key = hexdigest(key) cache.set(key, entries, ttl) end |