Class MemCache
In: lib/memcache.rb
Parent: Object

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.

In particular, the methods of this class are not thread safe. The calling application is responsible for implementing any necessary locking if a cache object will be called from multiple threads.

Methods

[]   []=   active?   delete   get   get_server_for_key   inspect   make_cache_key   new   readonly?   reset   servers=   set  

Classes and Modules

Class MemCache::ClientError
Class MemCache::InternalError
Class MemCache::MemCacheError
Class MemCache::Server
Class MemCache::ServerError

Constants

GENERAL_ERROR = /^ERROR\r\n/   Patterns for matching against server error replies.
CLIENT_ERROR = /^CLIENT_ERROR/
SERVER_ERROR = /^SERVER_ERROR/
DEFAULT_OPTIONS = { :namespace => nil, :readonly => false   Default options for the cache object.
DEFAULT_PORT = 11211   Default memcached port.
DEFAULT_WEIGHT = 1   Default memcached server weight.

Attributes

request_timeout  [RW]  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.

Public Class methods

Valid options are:

    :namespace
        If specified, all keys will have the given value prepended
        before accessing the cache.  Defaults to nil.

    :readonly
        If this is set, any attempt to write to the cache will generate
        an exception.  Defaults to false.

Public Instance methods

Shortcut to get a value from the cache.

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.

Returns whether there is at least one active server for the object.

Remove an entry from the cache.

Return a string representation of the cache object.

Returns whether the cache was created read only.

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.

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.

Add an entry to the cache.

Protected Instance methods

Pick a server to handle the request based on a hash of the key.

Create a key for the cache, incorporating the namespace qualifier if requested.

[Validate]