Class

MemCache

Extends:

A Ruby client library for memcached.

This is intended to provide access to basic memcached functionality. It does not attempt to be complete implementation of the entire API, but it is approaching a complete implementation.

Classes
MemCacheError Base MemCache exception class.
Server This class represents a memcached server instance.
Constants
DEFAULT_OPTIONS Default options for the cache object.
DEFAULT_PORT Default memcached port.
DEFAULT_WEIGHT Default memcached server weight.
VERSION The version of MemCache you are using.
Public Attributes
multithread The multithread setting for this instance
namespace The namespace for this instance
request_timeout The amount of time to wait for a response from a memcached server. If a response is not completed within this time, the connection to the server will be closed and an error will be raised.
servers The servers this client talks to. Play at your own peril.
Public Methods
[] Alias for #get
[]= Shortcut to save a value in the cache. This method does not set an expiration on the entry. Use set to specify an explicit expiry.
active? Returns whether there is at least one active server for the object.
add Add key to the cache with value value that expires in expiry seconds, but only if key does not already exist in the cache. If raw is true, value will not be Marshalled.
decr Deceremets the value for key by amount and returns the new value. key must already exist. If key is not an integer, it is assumed to be
delete Removes key from the cache in expiry seconds.
flush_all Flush the cache from all memcache servers.
get Retrieves key from memcache. If raw is false, the value will be unmarshalled.
get_multi Retrieves multiple values from memcached in parallel, if possible.
incr Increments the value for key by amount and retruns the new value. key must already exist. If key is not an integer, it is assumed to be 0.
inspect Returns a string representation of the cache object.
new Accepts a list of servers and a list of opts. servers may be omitted. See +servers=+ for acceptable server list arguments.
readonly? Returns whether or not the cache object was created read only.
reset Reset the connection to all memcache servers. This should be called if there is a problem with a cache lookup that might have left the connection in a corrupted state.
servers= Set the servers that the requests will be distributed between. Entries can be either strings of the form "hostname:port" or "hostname:port:weight" or MemCache::Server objects.
set Add key to the cache with value value that expires in expiry seconds. If raw is true, value will not be Marshalled.
stats Returns statistics for each memcached server. An explanation of the statistics can be found in the memcached docs:
Protected Methods
cache_decr Performs a raw decr for cache_key from server. Returns nil if not found.
cache_get Fetches the raw data for cache_key from server. Returns nil on cache miss.
cache_get_multi Fetches cache_keys from server using a multi-get.
cache_incr Performs a raw incr for cache_key from server. Returns nil if not found.
get_server_for_key Pick a server to handle the request based on a hash of the key.
handle_error Handles error from server.
hash_for Returns an interoperable hash value for key. (I think, docs are sketchy for down servers).
make_cache_key Create a key for the cache, incorporating the namespace qualifier if requested.
raise_on_error_response!
request_setup Performs setup for making a request with key from memcached. Returns the server to fetch the key from and the complete key to use.
threadsafe_cache_decr
threadsafe_cache_get
threadsafe_cache_get_multi
threadsafe_cache_incr
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.