class Cache

Helper methods for cache.

Hierarchy

  • class \Drupal\Core\Cache\Cache

Expanded class hierarchy of Cache

7 files declare their use of Cache
cache.inc in drupal/core/includes/cache.inc
Functions and interfaces for cache handling.
ClearTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/ClearTest.php
Definition of Drupal\system\Tests\Cache\ClearTest.
common.inc in drupal/core/includes/common.inc
Common functions that many Drupal modules will need to reference.
NodeBulkForm.php in drupal/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php
Contains \Drupal\node\Plugin\views\field\NodeBulkForm.
SaveComment.php in drupal/core/modules/comment/lib/Drupal/comment/Plugin/Action/SaveComment.php
Contains \Drupal\comment\Plugin\Action\SaveComment.

... See full list

9 string references to 'Cache'
BackendChainImplementationUnitTest::getInfo in drupal/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php
This method exists to support the simpletest UI runner.
BackendChainUnitTest::getInfo in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/BackendChainUnitTest.php
block.schema.yml in drupal/core/modules/block/config/schema/block.schema.yml
drupal/core/modules/block/config/schema/block.schema.yml
CacheTest::getInfo in drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php
ClearTest::getInfo in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/ClearTest.php

... See full list

File

drupal/core/lib/Drupal/Core/Cache/Cache.php, line 13
Contains \Drupal\Core\Cache\Cache.

Namespace

Drupal\Core\Cache
View source
class Cache {

  /**
   * Deletes items from all bins with any of the specified tags.
   *
   * Many sites have more than one active cache backend, and each backend may
   * use a different strategy for storing tags against cache items, and
   * deleting cache items associated with a given tag.
   *
   * When deleting a given list of tags, we iterate over each cache backend, and
   * and call deleteTags() on each.
   *
   * @param array $tags
   *   The list of tags to delete cache items for.
   */
  public static function deleteTags(array $tags) {
    foreach (static::getBins() as $cache_backend) {
      $cache_backend
        ->deleteTags($tags);
    }
  }

  /**
   * Marks cache items from all bins with any of the specified tags as invalid.
   *
   * Many sites have more than one active cache backend, and each backend my use
   * a different strategy for storing tags against cache items, and invalidating
   * cache items associated with a given tag.
   *
   * When invalidating a given list of tags, we iterate over each cache backend,
   * and call invalidateTags() on each.
   *
   * @param array $tags
   *   The list of tags to invalidate cache items for.
   */
  public static function invalidateTags(array $tags) {
    foreach (static::getBins() as $cache_backend) {
      $cache_backend
        ->invalidateTags($tags);
    }
  }

  /**
   * Gets all cache bin services.
   *
   * @return array
   *  An array of cache backend objects keyed by cache bins.
   */
  public static function getBins() {
    $bins = array();
    $container = \Drupal::getContainer();
    foreach ($container
      ->getParameter('cache_bins') as $service_id => $bin) {
      $bins[$bin] = $container
        ->get($service_id);
    }
    return $bins;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Cache::deleteTags public static function Deletes items from all bins with any of the specified tags.
Cache::getBins public static function Gets all cache bin services.
Cache::invalidateTags public static function Marks cache items from all bins with any of the specified tags as invalid.