You are here

class MemcacheStoragePageCache in Memcache Storage 7

Class handles memcached cache objects.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
MemcacheStorage::$bin protected property Name of cache bin. Example: 'cache' or 'cache_page', etc.
MemcacheStorage::$cache_ids protected property List of all cache ids in the current cache bin.
MemcacheStorage::$wildcards protected property List of wildcards for the current cache bin.
MemcacheStorage::addCacheID protected function Add cache ID to the list of cache IDs which are used in the cache bin.
MemcacheStorage::cacheBinName public function Returns a cache bin name with namespace prefix.
MemcacheStorage::get function Implements DrupalCacheInterface::get(). Overrides DrupalCacheInterface::get
MemcacheStorage::getBinIndex protected function Load cache bin index. This index is part of memcache key and changes if cache bin should be cleared.
MemcacheStorage::getCacheIDs public function Returns a list of cache ids which are currently in use.
MemcacheStorage::getWildcards public function Returns a list of wildcard flushes for the current cache bin which has not been invalidated yet.
MemcacheStorage::increaseBinIndex protected function Increase cache bin index. This operation changes all memcache keys in selected cache bin so we simulate cache flush for it.
MemcacheStorage::isEmpty function Implements DrupalCacheInterface::isEmpty(). Overrides DrupalCacheInterface::isEmpty
MemcacheStorage::removeCacheID protected function Remove cache ID from the list of cache IDs which are used in the cache bin.
MemcacheStorage::removeCacheIDs protected function Remove list of cache IDs from the list of cache IDs which are used in the cache bin.
MemcacheStorage::validateItem protected function Validates cache item. Checks if it is still valid and not expired.
MemcacheStorage::__construct function Constructs a new MemcacheStorage object.
MemcacheStoragePageCache::clear function Implements DrupalCacheInterface::clear(). Overrides MemcacheStorage::clear
MemcacheStoragePageCache::getMultiple function Ovirrides MemcacheStorage::getMultiple(). Overrides MemcacheStorage::getMultiple
MemcacheStoragePageCache::set function Ovirrides MemcacheStorage::set(). Overrides MemcacheStorage::set