Class: Rack::Cache::MetaStore::MemCached
- Inherits:
-
MemCacheBase
- Object
- Rack::Cache::MetaStore
- MemCacheBase
- Rack::Cache::MetaStore::MemCached
- Defined in:
- lib/rack/cache/meta_store.rb
Constant Summary
Constants inherited from Rack::Cache::MetaStore
DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
The Memcached instance used to communicated with the memcached daemon.
Instance Method Summary collapse
-
#initialize(server = "localhost:11211", options = {}) ⇒ MemCached
constructor
A new instance of MemCached.
- #purge(key) ⇒ Object
- #read(key) ⇒ Object
-
#write(key, entries, ttl = 0) ⇒ Object
Default TTL to zero, interpreted as “don’t expire” by Memcached.
Methods inherited from MemCacheBase
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.
367 368 369 370 371 372 373 374 375 376 |
# File 'lib/rack/cache/meta_store.rb', line 367 def initialize(server="localhost:11211", ={}) [:prefix_key] ||= .delete(:namespace) if .key?(:namespace) @cache = if server.respond_to?(:stats) server else require 'memcached' Memcached.new(server, ) end end |
Instance Attribute Details
#cache ⇒ Object (readonly)
The Memcached instance used to communicated with the memcached daemon.
365 366 367 |
# File 'lib/rack/cache/meta_store.rb', line 365 def cache @cache end |
Instance Method Details
#purge(key) ⇒ Object
391 392 393 394 395 396 397 |
# File 'lib/rack/cache/meta_store.rb', line 391 def purge(key) key = hexdigest(key) cache.delete(key) nil rescue Memcached::NotFound nil end |
#read(key) ⇒ Object
378 379 380 381 382 383 |
# File 'lib/rack/cache/meta_store.rb', line 378 def read(key) key = hexdigest(key) cache.get(key) rescue Memcached::NotFound [] end |
#write(key, entries, ttl = 0) ⇒ Object
Default TTL to zero, interpreted as “don’t expire” by Memcached.
386 387 388 389 |
# File 'lib/rack/cache/meta_store.rb', line 386 def write(key, entries, ttl = 0) key = hexdigest(key) cache.set(key, entries, ttl) end |