class Tripod::CacheStores::MemcachedCacheStore

A Tripod::CacheStore that uses Memcached. Note: Make sure you set the memcached -I (slab size) to big enough to store each result, and set the -m (total size) to something quite big (or the cache will recycle too often).

Public Class Methods

new(location, size = 1) click to toggle source

initialize a memcached cache store at the specified port (default 'localhost:11211') a pool size should also be specified (defaults to 1 for development/local use reasons)

# File lib/tripod/cache_stores/memcached_cache_store.rb, line 14
def initialize(location, size = 1)
  @dalli_pool = ConnectionPool.new(:size => size, :timeout => 3) { Dalli::Client.new(location, :value_max_bytes => Tripod.response_limit_bytes) }
end

Public Instance Methods

clear!() click to toggle source
# File lib/tripod/cache_stores/memcached_cache_store.rb, line 53
def clear!
  @dalli_pool.with do |client|
    client.flush
  end
end
exist?(key) click to toggle source
# File lib/tripod/cache_stores/memcached_cache_store.rb, line 27
def exist?(key)
  @dalli_pool.with do |client|
    !!client.get(key)
  end
end
fetch(key) { || ... } click to toggle source

 takes a block

# File lib/tripod/cache_stores/memcached_cache_store.rb, line 19
def fetch(key)
  raise ArgumentError.new("expected a block") unless block_given?

  @dalli_pool.with do |client|
    client.fetch(key) { yield }
  end
end
read(key) click to toggle source
# File lib/tripod/cache_stores/memcached_cache_store.rb, line 39
def read(key)
  @dalli_pool.with do |client|
    client.get(key)
  end
end
stats() click to toggle source
# File lib/tripod/cache_stores/memcached_cache_store.rb, line 45
def stats
  output = []
  @dalli_pool.with do |client|
    output << client.stats
  end
  output
end
write(key, data) click to toggle source
# File lib/tripod/cache_stores/memcached_cache_store.rb, line 33
def write(key, data)
  @dalli_pool.with do |client|
    client.set(key, data)
  end
end