Class: Rack::Cache::MetaStore::Dalli

Inherits:
MemCacheBase show all
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

#cache

Instance Method Summary collapse

Methods inherited from MemCacheBase

resolve

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.



336
337
338
339
340
341
342
343
344
# File 'lib/rack/cache/meta_store.rb', line 336

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

#purge(key) ⇒ Object



357
358
359
360
# File 'lib/rack/cache/meta_store.rb', line 357

def purge(key)
  cache.delete(hexdigest(key))
  nil
end

#read(key) ⇒ Object



346
347
348
349
# File 'lib/rack/cache/meta_store.rb', line 346

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.



352
353
354
355
# File 'lib/rack/cache/meta_store.rb', line 352

def write(key, entries, ttl = 0)
  key = hexdigest(key)
  cache.set(key, entries, ttl)
end