interface DrupalCacheInterface

Defines an interface for cache implementations.

All cache implementations have to implement this interface. DrupalDatabaseCache provides the default implementation, which can be consulted as an example.

To make Drupal use your implementation for a certain cache bin, you have to set a variable with the name of the cache bin as its key and the name of your class as its value. For example, if your implementation of DrupalCacheInterface was called MyCustomCache, the following line would make Drupal use it for the 'cache_page' bin:

 variable_set('cache_class_cache_page', 'MyCustomCache');

Additionally, you can register your cache implementation to be used by default for all cache bins by setting the variable 'cache_default_class' to the name of your implementation of the DrupalCacheInterface, e.g.

 variable_set('cache_default_class', 'MyCustomCache');

To implement a completely custom cache bin, use the same variable format:

 variable_set('cache_class_custom_bin', 'MyCustomCache');

To access your custom cache bin, specify the name of the bin when storing or retrieving cached data:

 cache_set($cid, $data, 'custom_bin', $expire);
 cache_get($cid, 'custom_bin');

Hierarchy

Expanded class hierarchy of DrupalCacheInterface

All classes that implement DrupalCacheInterface

See also

_cache_get_object()

DrupalDatabaseCache

File

includes/cache.inc, line 224
Functions and interfaces for cache handling.

Members

Name Modifiers Type Description
DrupalCacheInterface::clear function Expires data from the cache.
DrupalCacheInterface::get function Returns data from the persistent cache.
DrupalCacheInterface::getMultiple function Returns data from the persistent cache when given an array of cache IDs.
DrupalCacheInterface::isEmpty function Checks if a cache bin is empty.
DrupalCacheInterface::set function Stores data in the persistent cache.

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!cache.inc/interface/DrupalCacheInterface/7.x