Class: Tripod::CacheStores::MemcachedCacheStore
- Inherits:
-
Object
- Object
- Tripod::CacheStores::MemcachedCacheStore
- 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
- #clear! ⇒ Object
- #exist?(key) ⇒ Boolean
-
#fetch(key) ⇒ Object
takes a block.
-
#initialize(location) ⇒ MemcachedCacheStore
constructor
initialize a memcached cache store at the specified port (default ‘localhost:11211’).
- #read(key) ⇒ Object
- #write(key, data) ⇒ Object
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, :value_max_bytes => Tripod.response_limit_bytes) end |
Instance Method Details
#clear! ⇒ Object
37 38 39 |
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 37 def clear! @dalli.flush end |
#exist?(key) ⇒ Boolean
25 26 27 |
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 25 def exist?(key) !!@dalli.get(key) end |
#fetch(key) ⇒ Object
takes a block
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
33 34 35 |
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 33 def read(key) @dalli.get(key) end |
#write(key, data) ⇒ Object
29 30 31 |
# File 'lib/tripod/cache_stores/memcached_cache_store.rb', line 29 def write(key, data) @dalli.set(key, data) end |