Inheritances
Files
Overview
FRAMES
NO FRAMES

Class Zend_Cache_Backend_Memcached

Zend_Cache_Backend
|
Zend_Cache_Backend_Memcached
PackageZend_Cache
SubpackageZend_Cache_Backend
CopyrightCopyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
Licensehttp://framework.zend.com/license/new-bsd New BSD License

Summary

Class constants
DEFAULT_HOST Default Values
DEFAULT_PORT
DEFAULT_PERSISTENT
DEFAULT_WEIGHT
DEFAULT_TIMEOUT
DEFAULT_RETRY_INTERVAL
DEFAULT_STATUS
DEFAULT_FAILURE_CALLBACK
TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND Log message
TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND
Instance fields
# $_memcache Memcache object
# $_options Available options
Instance methods
+ __construct() Constructor
+ clean() Clean some cache records
+ getCapabilities() Return an associative array of capabilities (booleans) of the backend
+ getFillingPercentage() Return the filling percentage of the backend storage
+ getIds() Return an array of stored cache ids
+ getIdsMatchingAnyTags() Return an array of stored cache ids which match any given tags
+ getIdsMatchingTags() Return an array of stored cache ids which match given tags
+ getIdsNotMatchingTags() Return an array of stored cache ids which don't match given tags
+ getMetadatas() Return an array of metadatas for the given cache id
+ getTags() Return an array of stored tags
+ isAutomaticCleaningAvailable() Return true if the automatic cleaning is available for the backend
+ load() Test if a cache is available for the given id and (if yes) return it (false else)
+ remove() Remove a cache record
+ save() Save some string datas into a cache record
+ setDirectives() Set the frontend directives
+ test() Test if a cache is available or not (for the given id)
+ touch() Give (if possible) an extra lifetime to the given cache id

Details

Class constants

DEFAULT_HOST
const DEFAULT_HOST = '127.0.0.1'
Default Values
DEFAULT_PORT
const DEFAULT_PORT = 11211
DEFAULT_PERSISTENT
const DEFAULT_PERSISTENT = true
DEFAULT_WEIGHT
const DEFAULT_WEIGHT = 1
DEFAULT_TIMEOUT
const DEFAULT_TIMEOUT = 1
DEFAULT_RETRY_INTERVAL
const DEFAULT_RETRY_INTERVAL = 15
DEFAULT_STATUS
const DEFAULT_STATUS = true
DEFAULT_FAILURE_CALLBACK
const DEFAULT_FAILURE_CALLBACK = null
TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend'
Log message
TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend'

Instance fields

$_memcache
protected $_memcache = null
Memcache object
Var mixed memcache object
$_options
protected $_options = array( 'servers' => array(array( 'host' => self::DEFAULT_HOST, 'port' => self::DEFAULT_PORT, 'persistent' => self::DEFAULT_PERSISTENT, 'weight' => self::DEFAULT_WEIGHT, 'timeout' => self::DEFAULT_TIMEOUT, 'retry_interval' => self::DEFAULT_RETRY_INTERVAL, 'status' => self::DEFAULT_STATUS, 'failure_callback' => self::DEFAULT_FAILURE_CALLBACK )), 'compression' => false, 'compatibility' => false, )
Available options

=====> (array) servers :
an array of memcached server ; each memcached server is described by an associative array :
'host' => (string) : the name of the memcached server
'port' => (int) : the port of the memcached server
'persistent' => (bool) : use or not persistent connections to this memcached server
'weight' => (int) : number of buckets to create for this server which in turn control its
probability of it being selected. The probability is relative to the total
weight of all servers.
'timeout' => (int) : value in seconds which will be used for connecting to the daemon. Think twice
before changing the default value of 1 second - you can lose all the
advantages of caching if your connection is too slow.
'retry_interval' => (int) : controls how often a failed server will be retried, the default value
is 15 seconds. Setting this parameter to -1 disables automatic retry.
'status' => (bool) : controls if the server should be flagged as online.
'failure_callback' => (callback) : Allows the user to specify a callback function to run upon
encountering an error. The callback is run before failover
is attempted. The function takes two parameters, the hostname
and port of the failed server.

=====> (boolean) compression :
true if you want to use on-the-fly compression

=====> (boolean) compatibility :
true if you use old memcache server or extension
Var array available options

Instance methods

__construct()
public function __construct( array $options = array())
Constructor
Parameters
array $options
Returns void
clean()
public function clean( $mode = Zend_Cache::CLEANING_MODE_ALL
$tags = array()
)
Clean some cache records

Available modes are :
'all' (default) => remove all cache entries ($tags is not used)
'old' => unsupported
'matchingTag' => unsupported
'notMatchingTag' => unsupported
'matchingAnyTag' => unsupported
Parameters
string $mode Clean mode
array $tags Array of tags
Returns boolean True if no problem
getCapabilities()
public function getCapabilities( )
Return an associative array of capabilities (booleans) of the backend

The array must include these keys :
- automatic_cleaning (is automating cleaning necessary)
- tags (are tags supported)
- expired_read (is it possible to read expired cache records
(for doNotTestCacheValidity option for example))
- priority does the backend deal with priority when saving
- infinite_lifetime (is infinite lifetime can work with this backend)
- get_list (is it possible to get the list of cache ids and the complete list of tags)
Returns array associative of with capabilities
getFillingPercentage()
public function getFillingPercentage( )
Return the filling percentage of the backend storage
Returns int integer between 0 and 100
getIds()
public function getIds( )
Return an array of stored cache ids
Returns array array of stored cache ids (string)
getIdsMatchingAnyTags()
public function getIdsMatchingAnyTags( $tags = array())
Return an array of stored cache ids which match any given tags

In case of multiple tags, a logical AND is made between tags
Parameters
array $tags array of tags
Returns array array of any matching cache ids (string)
getIdsMatchingTags()
public function getIdsMatchingTags( $tags = array())
Return an array of stored cache ids which match given tags

In case of multiple tags, a logical AND is made between tags
Parameters
array $tags array of tags
Returns array array of matching cache ids (string)
getIdsNotMatchingTags()
public function getIdsNotMatchingTags( $tags = array())
Return an array of stored cache ids which don't match given tags

In case of multiple tags, a logical OR is made between tags
Parameters
array $tags array of tags
Returns array array of not matching cache ids (string)
getMetadatas()
public function getMetadatas( $id)
Return an array of metadatas for the given cache id

The array must include these keys :
- expire : the expire timestamp
- tags : a string array of tags
- mtime : timestamp of last modification time
Parameters
string $id cache id
Returns array array of metadatas (false if the cache id is not found)
getTags()
public function getTags( )
Return an array of stored tags
Returns array array of stored tags (string)
isAutomaticCleaningAvailable()
public function isAutomaticCleaningAvailable( )
Return true if the automatic cleaning is available for the backend
Returns boolean
load()
public function load( $id
$doNotTestCacheValidity = false
)
Test if a cache is available for the given id and (if yes) return it (false else)
Parameters
string $id Cache id
boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
Returns string|false cached datas
remove()
public function remove( $id)
Remove a cache record
Parameters
string $id Cache id
Returns boolean True if no problem
save()
public function save( $data
$id
$tags = array()
$specificLifetime = false
)
Save some string datas into a cache record

Note : $data is always "string" (serialization is done by the
core not by the backend)
Parameters
string $data Datas to cache
string $id Cache id
array $tags Array of strings, the cache record will be tagged by each string entry
int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
Returns boolean True if no problem
setDirectives()
public function setDirectives( $directives)
Set the frontend directives
Parameters
array $directives Assoc of directives
Returns void
test()
public function test( $id)
Test if a cache is available or not (for the given id)
Parameters
string $id Cache id
Returns mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
touch()
public function touch( $id
$extraLifetime
)
Give (if possible) an extra lifetime to the given cache id
Parameters
string $id cache id
int $extraLifetime
Returns boolean true if ok