Class: Rack::Cache::MetaStore::MemCached

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 collapse

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 = {}) ⇒ MemCached

Returns a new instance of MemCached.



343
344
345
346
347
348
349
350
351
352
# File 'lib/rack/cache/metastore.rb', line 343

def initialize(server="localhost:11211", options={})
  options[:prefix_key] ||= options.delete(:namespace) if options.key?(:namespace)
  @cache =
    if server.respond_to?(:stats)
      server
    else
      require 'memcached'
      Memcached.new(server, options)
    end
end

Instance Attribute Details

#cacheObject (readonly)

The Memcached instance used to communicated with the memcached daemon.



341
342
343
# File 'lib/rack/cache/metastore.rb', line 341

def cache
  @cache
end

Instance Method Details

#purge(key) ⇒ Object



366
367
368
369
370
371
372
# File 'lib/rack/cache/metastore.rb', line 366

def purge(key)
  key = hexdigest(key)
  cache.delete(key)
  nil
rescue Memcached::NotFound
  nil
end

#read(key) ⇒ Object



354
355
356
357
358
359
# File 'lib/rack/cache/metastore.rb', line 354

def read(key)
  key = hexdigest(key)
  cache.get(key)
rescue Memcached::NotFound
  []
end

#write(key, entries) ⇒ Object



361
362
363
364
# File 'lib/rack/cache/metastore.rb', line 361

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