You are here

class CacheManager in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/CacheManager/CacheManager.php \Drupal\xautoload\CacheManager\CacheManager

Hierarchy

Expanded class hierarchy of CacheManager

3 files declare their use of CacheManager
AbstractCachedClassLoader.php in lib/ClassLoader/AbstractCachedClassLoader.php
ServiceContainerInterface.php in lib/DIC/ServiceContainerInterface.php
ServiceFactory.php in lib/DIC/ServiceFactory.php

File

lib/CacheManager/CacheManager.php, line 7

Namespace

Drupal\xautoload\CacheManager
View source
class CacheManager {

  /**
   * @var string
   */
  protected $prefix;

  /**
   * @var CacheManagerObserverInterface[]
   */
  protected $observers = array();

  /**
   * @param $prefix
   */
  protected function __construct($prefix) {
    $this->prefix = $prefix;
  }

  /**
   * This method has side effects, so it is not the constructor.
   *
   * @return CacheManager
   */
  static function create() {
    $prefix = variable_get('xautoload_cache_prefix', NULL);
    $manager = new self($prefix);
    if (empty($prefix)) {
      $manager
        ->renewCachePrefix();
    }
    return $manager;
  }

  /**
   * @param CacheManagerObserverInterface $observer
   */
  function observeCachePrefix($observer) {
    $observer
      ->setCachePrefix($this->prefix);
    $this->observers[] = $observer;
  }

  /**
   * Renew the cache prefix, save it, and notify all observers.
   */
  function renewCachePrefix() {
    $this->prefix = Util::randomString();
    variable_set('xautoload_cache_prefix', $this->prefix);
    foreach ($this->observers as $observer) {
      $observer
        ->setCachePrefix($this->prefix);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheManager::$observers protected property
CacheManager::$prefix protected property
CacheManager::create static function This method has side effects, so it is not the constructor.
CacheManager::observeCachePrefix function
CacheManager::renewCachePrefix function Renew the cache prefix, save it, and notify all observers.
CacheManager::__construct protected function