Class: Rack::Cache::MetaStore::MemCache

Inherits:
MemCacheBase show all
Defined in:
lib/rack/cache/metastore.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 = {}) ⇒ MemCache

Returns a new instance of MemCache.



294
295
296
297
298
299
300
301
302
# File 'lib/rack/cache/metastore.rb', line 294

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

#purge(key) ⇒ Object



314
315
316
317
# File 'lib/rack/cache/metastore.rb', line 314

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

#read(key) ⇒ Object



304
305
306
307
# File 'lib/rack/cache/metastore.rb', line 304

def read(key)
  key = hexdigest(key)
  cache.get(key) || []
end

#write(key, entries) ⇒ Object



309
310
311
312
# File 'lib/rack/cache/metastore.rb', line 309

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