Class: Rack::Cache::MetaStore::MemCacheBase

Inherits:
Rack::Cache::MetaStore show all
Extended by:
Utils
Defined in:
lib/rack/cache/meta_store.rb

Overview

Stores request/response pairs in memcached. Keys are not stored directly since memcached has a 250-byte limit on key names. Instead, the SHA1 hexdigest of the key is used.

Direct Known Subclasses

Dalli, MemCached

Constant Summary

Constants inherited from Rack::Cache::MetaStore

DISK, FILE, GAE, GAECACHE, HEAP, MEM, MEMCACHE, MEMCACHED

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Rack::Cache::MetaStore

#cache_key, #invalidate, #lookup, #store

Instance Attribute Details

#cacheObject (readonly)

The MemCache object used to communicated with the memcached daemon.



300
301
302
# File 'lib/rack/cache/meta_store.rb', line 300

def cache
  @cache
end

Class Method Details

.resolve(uri) ⇒ Object

Create MemCache store for the given URI. The URI must specify a host and may specify a port, namespace, and options:

memcached://example.com:11211/namespace?opt1=val1&opt2=val2

Query parameter names and values are documented with the memcached library: tinyurl.com/4upqnd



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/rack/cache/meta_store.rb', line 309

def self.resolve(uri)
  if uri.respond_to?(:scheme)
    server = "#{uri.host}:#{uri.port || '11211'}"
    options = parse_query(uri.query)
    options.keys.each do |key|
      value =
        case value = options.delete(key)
        when 'true' ; true
        when 'false' ; false
        else value.to_sym
        end
      options[key.to_sym] = value
    end

    options[:namespace] = uri.path.to_s.sub(/^\//, '')

    new server, options
  else
    # if the object provided is not a URI, pass it straight through
    # to the underlying implementation.
    new uri
  end
end