Class: Rack::Cache::MetaStore::MemCached
- Inherits:
-
MemCacheBase
- Object
- Rack::Cache::MetaStore
- MemCacheBase
- Rack::Cache::MetaStore::MemCached
- Defined in:
- lib/rack/cache/metastore.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) ⇒ Object
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.
337 338 339 340 341 342 343 344 345 |
# File 'lib/rack/cache/metastore.rb', line 337 def initialize(server="localhost:11211", ={}) @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.
335 336 337 |
# File 'lib/rack/cache/metastore.rb', line 335 def cache @cache end |
Instance Method Details
#purge(key) ⇒ Object
359 360 361 362 363 364 365 |
# File 'lib/rack/cache/metastore.rb', line 359 def purge(key) key = hexdigest(key) cache.delete(key) nil rescue Memcached::NotFound nil end |
#read(key) ⇒ Object
347 348 349 350 351 352 |
# File 'lib/rack/cache/metastore.rb', line 347 def read(key) key = hexdigest(key) cache.get(key) rescue Memcached::NotFound [] end |
#write(key, entries) ⇒ Object
354 355 356 357 |
# File 'lib/rack/cache/metastore.rb', line 354 def write(key, entries) key = hexdigest(key) cache.set(key, entries) end |