function MemcacheStoragePageCache::set in Memcache Storage 7
Ovirrides MemcacheStorage::set().
Overrides MemcacheStorage::set
File
- ./
memcache_storage.page_cache.inc, line 39 - Provides class for memcached data handling within cache_page bin.
Class
- MemcacheStoragePageCache
- Class handles memcached cache objects.
Code
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);
}