class Rack::Cache::MetaStore::MemCached

Attributes

cache[R]

The Memcached instance used to communicated with the memcached daemon.

Public Class Methods

new(server="localhost:11211", options={}) click to toggle source
# File lib/rack/cache/meta_store.rb, line 368
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

Public Instance Methods

purge(key) click to toggle source
# File lib/rack/cache/meta_store.rb, line 392
def purge(key)
  key = hexdigest(key)
  cache.delete(key)
  nil
rescue Memcached::NotFound
  nil
end
read(key) click to toggle source
# File lib/rack/cache/meta_store.rb, line 379
def read(key)
  key = hexdigest(key)
  cache.get(key)
rescue Memcached::NotFound
  []
end
write(key, entries, ttl = 0) click to toggle source

Default TTL to zero, interpreted as “don't expire” by Memcached.

# File lib/rack/cache/meta_store.rb, line 387
def write(key, entries, ttl = 0)
  key = hexdigest(key)
  cache.set(key, entries, ttl)
end