Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

DrupalCacheArray (moved to \Drupal\Core\Utility\CacheArray in Drupal 8) has been introduced in Drupal 7 with the main design goal to keep backwards-compatibility for large arrays while optimizing memory usage, so that only the subset that is actually used has to be loaded and kept in memory. The initial use case for that were the schema definitions, which used to be kept in a simple array, now only the tables that are actually needed are loaded.

\Drupal\Core\Cache\CacheCollector is the Drupal 8 replacement which no longer relies on ArrayAccess to act as an array but provides methods like get(), set() and delete(), as defined in the interface CacheCollectorInterface. The new implementation also supports to keep the cache when items are changed or deleted and it relies on the cache invalidation API to handle concurrent requests better.

It can be used by providing a subclass that implements the abstract method resolveCacheMiss() whose job it is to load a data item if it is not yet stored in the cache.

  /**
   * {@inheritdoc}
   */
  public function resolveCacheMiss($root) {
    $query = $this->connection->select('url_alias', 'u');
    $query->addExpression(1);
    $exists = (bool) $query
      ->condition('u.source', $this->connection->escapeLike($root) . '%', 'LIKE')
      ->range(0, 1)
      ->execute()
      ->fetchField();
    $this->storage[$root] = $exists;
    $this->persist($root);
    if ($exists) {
      return TRUE;
    }
  }

If implementations are a service, they need to tag the service with needs_destruction, so that updated caches are automatically persisted at the end of the request.

path.alias_whitelist:
    class: Drupal\Core\Path\AliasWhitelist
    tags:
      - { name: needs_destruction }

Examples implementations are:

CacheArray has been removed from Drupal 8.

Impacts: 
Site builders, administrators, editors