Class: Tripod::CacheStores::MemcachedCacheStore

Inherits:
Object
  • Object
show all
Defined in:
lib/tripod/cache_stores/memcached_cache_store.rb

Overview

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).

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ MemcachedCacheStore

initialize a memcached cache store at the specified port (default ‘localhost:11211’)



12
13
14
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 12

def initialize(location)
  @dalli = Dalli::Client.new(location)
end

Instance Method Details

#fetch(key) ⇒ Object

 takes a block

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 17

def fetch(key)
  raise ArgumentError.new("expected a block") unless block_given?

  @dalli.fetch(key) do
    yield
  end
end

#read(key) ⇒ Object



29
30
31
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 29

def read(key)
  @dalli.get(key)
end

#write(key, data) ⇒ Object



25
26
27
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 25

def write(key, data)
  @dalli.set(key, data)
end