class MemcacheStoragePageCache in Memcache Storage 7
Class handles memcached cache objects.
Hierarchy
- class \MemcacheStorage implements DrupalCacheInterface
- class \MemcacheStoragePageCache implements DrupalCacheInterface
Expanded class hierarchy of MemcacheStoragePageCache
File
- ./
memcache_storage.page_cache.inc, line 20 - Provides class for memcached data handling within cache_page bin.
View source
class MemcacheStoragePageCache extends MemcacheStorage implements DrupalCacheInterface {
/**
* Ovirrides MemcacheStorage::getMultiple().
*/
function getMultiple(&$cids) {
// No direct access to the cache if enabled external integration.
if (MEMCACHE_STORAGE_EXTERNAL_PAGE_CACHE) {
return array();
}
// Process page cache get as usual.
return parent::getMultiple($cids);
}
/**
* Ovirrides MemcacheStorage::set().
*/
function set($cid, $data, $expire = CACHE_PERMANENT) {
// Some servers (like Nginx) may access page cache directly from memcached pool
// to avoid passing request to the backend. But they only know how to get
// simple HTML string, not an objects. So we have to store simple HTML code.
if (MEMCACHE_STORAGE_EXTERNAL_PAGE_CACHE && !empty($data['body'])) {
// Make sure that page doesn't have 403 or 404 header.
// Otherwise nginx or varnish will deliver such pages with header
// 200, which is obviously wrong.
if (!empty($data['headers']['Status'])) {
$status = $data['headers']['Status'];
if (in_array($status, array(
'403 Forbidden',
'404 Not Found',
))) {
return FALSE;
}
}
// Developers may set custom expiration for cached pages in settings.php.
$custom_expiration = variable_get('memcache_storage_page_cache_custom_expiration', FALSE);
if ($custom_expiration) {
$expire = variable_get('memcache_storage_page_cache_expire', 0);
}
// Memcached supports TTL in second from current timestamp.
$expire = $expire > REQUEST_TIME ? $expire - REQUEST_TIME : $expire;
// Memcached doesn't support expiration values less than 0 (CACHE_PERMANENT).
$expire = $expire < CACHE_PERMANENT ? CACHE_PERMANENT : $expire;
return MemcacheStorageAPI::set($cid, $data['body'], $expire, $this->bin);
}
// Process cache set as usual.
return parent::set($cid, $data, $expire);
}
/**
* Implements DrupalCacheInterface::clear().
*/
function clear($cid = NULL, $wildcard = FALSE) {
// If enabled memcache storage external page cache we only may delete cache by key.
// This is because memcached doesn't support deletion by wildcard.
if (MEMCACHE_STORAGE_EXTERNAL_PAGE_CACHE && !empty($cid) && !$wildcard) {
// Convert string to an array to reduce amount of 'if-else' sections.
if (!is_array($cid)) {
$cid = array(
$cid,
);
}
// Remove HTML page from the cache_page bin.
foreach ($cid as $cache_id) {
MemcacheStorageAPI::delete($cache_id, $this->bin);
}
}
// Process cache deletion as usual.
return parent::clear($cid, $wildcard);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MemcacheStorage:: |
protected | property | Name of cache bin. Example: 'cache' or 'cache_page', etc. | |
MemcacheStorage:: |
protected | property | List of all cache ids in the current cache bin. | |
MemcacheStorage:: |
protected | property | List of wildcards for the current cache bin. | |
MemcacheStorage:: |
protected | function | Add cache ID to the list of cache IDs which are used in the cache bin. | |
MemcacheStorage:: |
public | function | Returns a cache bin name with namespace prefix. | |
MemcacheStorage:: |
function |
Implements DrupalCacheInterface::get(). Overrides DrupalCacheInterface:: |
||
MemcacheStorage:: |
protected | function | Load cache bin index. This index is part of memcache key and changes if cache bin should be cleared. | |
MemcacheStorage:: |
public | function | Returns a list of cache ids which are currently in use. | |
MemcacheStorage:: |
public | function | Returns a list of wildcard flushes for the current cache bin which has not been invalidated yet. | |
MemcacheStorage:: |
protected | function | Increase cache bin index. This operation changes all memcache keys in selected cache bin so we simulate cache flush for it. | |
MemcacheStorage:: |
function |
Implements DrupalCacheInterface::isEmpty(). Overrides DrupalCacheInterface:: |
||
MemcacheStorage:: |
protected | function | Remove cache ID from the list of cache IDs which are used in the cache bin. | |
MemcacheStorage:: |
protected | function | Remove list of cache IDs from the list of cache IDs which are used in the cache bin. | |
MemcacheStorage:: |
protected | function | Validates cache item. Checks if it is still valid and not expired. | |
MemcacheStorage:: |
function | Constructs a new MemcacheStorage object. | ||
MemcacheStoragePageCache:: |
function |
Implements DrupalCacheInterface::clear(). Overrides MemcacheStorage:: |
||
MemcacheStoragePageCache:: |
function |
Ovirrides MemcacheStorage::getMultiple(). Overrides MemcacheStorage:: |
||
MemcacheStoragePageCache:: |
function |
Ovirrides MemcacheStorage::set(). Overrides MemcacheStorage:: |