diff options
Diffstat (limited to 'includes/cache.inc')
-rw-r--r-- | includes/cache.inc | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/includes/cache.inc b/includes/cache.inc index 8666874ac..9b9ea600c 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -1,18 +1,23 @@ <?php /** - * Get the cache object for a cache bin. + * @file + * Functions and interfaces for cache handling. + */ + +/** + * Gets the cache object for a cache bin. * * By default, this returns an instance of the DrupalDatabaseCache class. * Classes implementing DrupalCacheInterface can register themselves both as a * default implementation and for specific bins. * - * @see DrupalCacheInterface - * * @param $bin * The cache bin for which the cache object should be returned. * @return DrupalCacheInterface * The cache object associated with the specified bin. + * + * @see DrupalCacheInterface */ function _cache_get_object($bin) { // We do not use drupal_static() here because we do not want to change the @@ -29,7 +34,7 @@ function _cache_get_object($bin) { } /** - * Return data from the persistent cache + * Returns data from the persistent cache. * * Data may be stored as either plain text or as serialized data. cache_get * will automatically return unserialized objects and arrays. @@ -50,13 +55,14 @@ function cache_get($cid, $bin = 'cache') { } /** - * Return data from the persistent cache when given an array of cache IDs. + * Returns data from the persistent cache when given an array of cache IDs. * * @param $cids * An array of cache IDs for the data to retrieve. This is passed by * reference, and will have the IDs successfully returned from cache removed. * @param $bin * The cache bin where the data is stored. + * * @return * An array of the items successfully returned from cache indexed by cid. */ @@ -65,7 +71,7 @@ function cache_get_multiple(array &$cids, $bin = 'cache') { } /** - * Store data in the persistent cache. + * Stores data in the persistent cache. * * The persistent cache is split up into several cache bins. In the default * cache implementation, each cache bin corresponds to a database table by the @@ -138,7 +144,7 @@ function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) { } /** - * Expire data from the cache. + * Expires data from the cache. * * If called without arguments, expirable entries will be cleared from the * cache_page and cache_block bins. @@ -146,15 +152,12 @@ function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) { * @param $cid * If set, the cache ID to delete. Otherwise, all cache entries that can * expire are deleted. - * * @param $bin - * If set, the bin $bin to delete from. Mandatory - * argument if $cid is set. - * + * If set, the cache bin to delete from. Mandatory argument if $cid is set. * @param $wildcard - * If $wildcard is TRUE, cache IDs starting with $cid are deleted in - * addition to the exact cache ID specified by $cid. If $wildcard is - * TRUE and $cid is '*' then the entire bin $bin is emptied. + * If TRUE, cache IDs starting with $cid are deleted in addition to the + * exact cache ID specified by $cid. If $wildcard is TRUE and $cid is '*', + * the entire cache bin is emptied. */ function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) { if (!isset($cid) && !isset($bin)) { @@ -170,13 +173,14 @@ function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) { } /** - * Check if a cache bin is empty. + * Checks if a cache bin is empty. * * A cache bin is considered empty if it does not contain any valid data for any * cache ID. * * @param $bin * The cache bin to check. + * * @return * TRUE if the cache bin specified is empty. */ @@ -185,7 +189,7 @@ function cache_is_empty($bin) { } /** - * Interface for cache implementations. + * Defines an interface for cache implementations. * * All cache implementations have to implement this interface. * DrupalDatabaseCache provides the default implementation, which can be @@ -223,7 +227,7 @@ function cache_is_empty($bin) { */ interface DrupalCacheInterface { /** - * Constructor. + * Constructs a new cache interface. * * @param $bin * The cache bin for which the object is created. @@ -231,31 +235,34 @@ interface DrupalCacheInterface { function __construct($bin); /** - * Return data from the persistent cache. Data may be stored as either plain - * text or as serialized data. cache_get will automatically return - * unserialized objects and arrays. + * Returns data from the persistent cache. + * + * Data may be stored as either plain text or as serialized data. cache_get() + * will automatically return unserialized objects and arrays. * * @param $cid * The cache ID of the data to retrieve. + * * @return * The cache or FALSE on failure. */ function get($cid); /** - * Return data from the persistent cache when given an array of cache IDs. + * Returns data from the persistent cache when given an array of cache IDs. * * @param $cids * An array of cache IDs for the data to retrieve. This is passed by * reference, and will have the IDs successfully returned from cache * removed. + * * @return * An array of the items successfully returned from cache indexed by cid. */ function getMultiple(&$cids); /** - * Store data in the persistent cache. + * Stores data in the persistent cache. * * @param $cid * The cache ID of the data to store. @@ -276,8 +283,10 @@ interface DrupalCacheInterface { /** - * Expire data from the cache. If called without arguments, expirable - * entries will be cleared from the cache_page and cache_block bins. + * Expires data from the cache. + * + * If called without arguments, expirable entries will be cleared from the + * cache_page and cache_block bins. * * @param $cid * If set, the cache ID to delete. Otherwise, all cache entries that can @@ -290,7 +299,7 @@ interface DrupalCacheInterface { function clear($cid = NULL, $wildcard = FALSE); /** - * Check if a cache bin is empty. + * Checks if a cache bin is empty. * * A cache bin is considered empty if it does not contain any valid data for * any cache ID. @@ -302,7 +311,7 @@ interface DrupalCacheInterface { } /** - * Default cache implementation. + * Defines a default cache implementation. * * This is Drupal's default cache implementation. It uses the database to store * cached data. Each cache bin corresponds to a database table by the same name. @@ -310,16 +319,25 @@ interface DrupalCacheInterface { class DrupalDatabaseCache implements DrupalCacheInterface { protected $bin; + /** + * Constructs a new DrupalDatabaseCache object. + */ function __construct($bin) { $this->bin = $bin; } + /** + * Implements DrupalCacheInterface::get(). + */ function get($cid) { $cids = array($cid); $cache = $this->getMultiple($cids); return reset($cache); } + /** + * Implements DrupalCacheInterface::getMultiple(). + */ function getMultiple(&$cids) { try { // Garbage collection necessary when enforcing a minimum cache lifetime. @@ -373,13 +391,14 @@ class DrupalDatabaseCache implements DrupalCacheInterface { } /** - * Prepare a cached item. + * Prepares a cached item. * * Checks that items are either permanent or did not expire, and unserializes * data as appropriate. * * @param $cache * An item loaded from cache_get() or cache_get_multiple(). + * * @return * The item with data unserialized as appropriate or FALSE if there is no * valid item to load. @@ -408,6 +427,9 @@ class DrupalDatabaseCache implements DrupalCacheInterface { return $cache; } + /** + * Implements DrupalCacheInterface::set(). + */ function set($cid, $data, $expire = CACHE_PERMANENT) { $fields = array( 'serialized' => 0, @@ -434,6 +456,9 @@ class DrupalDatabaseCache implements DrupalCacheInterface { } } + /** + * Implements DrupalCacheInterface::clear(). + */ function clear($cid = NULL, $wildcard = FALSE) { global $user; @@ -496,6 +521,9 @@ class DrupalDatabaseCache implements DrupalCacheInterface { } } + /** + * Implements DrupalCacheInterface::isEmpty(). + */ function isEmpty() { $this->garbageCollection(); $query = db_select($this->bin); |