You are here

class BoostCache in Boost 8

The BoostCache class.

@todo, only fire notices if debug (mode) enabled. @todo, batch to generate entire cache. @todo, cron to re-generate/ invalidate cache. @todo, exclude route list, don't cache specific paths.

Hierarchy

Expanded class hierarchy of BoostCache

1 file declares its use of BoostCache
BoostResponseSubscriber.php in src/EventSubscriber/BoostResponseSubscriber.php
Contains Drupal\boost\EventSubscriber\BoostResponseSubscriber

File

src/BoostCache.php, line 21
Contains Drupal\boost\BoostCache

Namespace

Drupal\boost
View source
class BoostCache {

  /**
   * @var \Drupal\boost\BoostCacheHandler
   */
  protected $handler;

  /**
   * @var \Drupal\boost\BoostCacheRoute
   */
  protected $route;

  /**
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Constructs a new BoostCache.
   */
  public function __construct() {
    $this->handler = new BoostCacheHandler();
    $this->route = new BoostCacheRoute(\Drupal::service('path.current'), \Drupal::service('path.alias_manager'));
    $this->logger = \Drupal::logger('boost');
  }

  /**
   * Save page to local filesystem.
   * @param string $response
   *
   *  @todo, _toString if Symfony Response.
   */
  public function index($response) {
    if (!is_string($response)) {
      $this->logger
        ->notice('Response for route @uri can not be cached.', array(
        '@uri' => $this->route
          ->getPath(),
      ));
      return;
    }
    $this->handler
      ->setCache($this->route
      ->getUri(), $response);
  }

  /**
   * Retrieve Boost cache file.
   */
  public function retrieve() {
    $uri = $this->route
      ->getUri();
    if (!file_exists($uri)) {
      $this->logger
        ->notice('Route @uri not cached.', array(
        '@uri' => $uri,
      ));
      return false;
    }
    return $this->handler
      ->getCache($uri);
  }

  /**
   * Delete individual cache file.
   */
  public function delete() {
    $uri = $this->route
      ->getUri();
    if (!file_exists($uri)) {
      return false;
    }
    return $this->handler
      ->deleteCache($uri);
  }

  /**
   * Delete entire boost cache.
   */
  public function purge() {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BoostCache::$handler protected property
BoostCache::$logger protected property
BoostCache::$route protected property
BoostCache::delete public function Delete individual cache file.
BoostCache::index public function Save page to local filesystem.
BoostCache::purge public function Delete entire boost cache.
BoostCache::retrieve public function Retrieve Boost cache file.
BoostCache::__construct public function Constructs a new BoostCache.