class BlockContentUuidLookup
A cache collector that caches IDs for block_content UUIDs.
As block_content entities are used as block plugin derivatives, it is a fairly safe limitation that there are not hundreds of them, a site will likely run into problems with too many block content entities in other places than a cache that only stores UUID's and IDs. The same assumption is not true for other content entities.
@internal
Hierarchy
- class \Drupal\Core\Cache\CacheCollector implements \Drupal\Core\Cache\CacheCollectorInterface, \Drupal\Core\DestructableInterface- class \Drupal\block_content\BlockContentUuidLookup extends \Drupal\Core\Cache\CacheCollector
 
Expanded class hierarchy of BlockContentUuidLookup
1 file declares its use of BlockContentUuidLookup
- BlockContentBlock.php in core/modules/ block_content/ src/ Plugin/ Block/ BlockContentBlock.php 
1 string reference to 'BlockContentUuidLookup'
- block_content.services.yml in core/modules/ block_content/ block_content.services.yml 
- core/modules/block_content/block_content.services.yml
1 service uses BlockContentUuidLookup
- block_content.uuid_lookup in core/modules/ block_content/ block_content.services.yml 
- \Drupal\block_content\BlockContentUuidLookup
File
- 
              core/modules/ block_content/ src/ BlockContentUuidLookup.php, line 21 
Namespace
Drupal\block_contentView source
class BlockContentUuidLookup extends CacheCollector {
  
  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;
  
  /**
   * Constructs a BlockContentUuidLookup instance.
   *
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache
   *   The cache backend.
   * @param \Drupal\Core\Lock\LockBackendInterface $lock
   *   The lock backend.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct('block_content_uuid', $cache, $lock);
    $this->entityTypeManager = $entity_type_manager;
  }
  
  /**
   * {@inheritdoc}
   */
  protected function resolveCacheMiss($key) {
    $ids = $this->entityTypeManager
      ->getStorage('block_content')
      ->getQuery()
      ->condition('uuid', $key)
      ->execute();
    // Only cache if there is a match, otherwise creating new entities would
    // require to invalidate the cache.
    $id = reset($ids);
    if ($id) {
      $this->storage[$key] = $id;
      $this->persist($key);
    }
    return $id;
  }
}Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|
| BlockContentUuidLookup::$entityTypeManager | protected | property | The entity type manager. | ||
| BlockContentUuidLookup::resolveCacheMiss | protected | function | Resolves a cache miss. | Overrides CacheCollector::resolveCacheMiss | |
| BlockContentUuidLookup::__construct | public | function | Constructs a BlockContentUuidLookup instance. | Overrides CacheCollector::__construct | |
| CacheCollector::$cache | protected | property | The cache backend that should be used. | 1 | |
| CacheCollector::$cacheCreated | protected | property | Stores the cache creation time. | ||
| CacheCollector::$cacheInvalidated | protected | property | Flag that indicates of the cache has been invalidated. | ||
| CacheCollector::$cacheLoaded | protected | property | Indicates if the collected cache was already loaded. | ||
| CacheCollector::$cid | protected | property | The cache id that is used for the cache entry. | ||
| CacheCollector::$keysToPersist | protected | property | An array of keys to add to the cache on service termination. | ||
| CacheCollector::$keysToRemove | protected | property | An array of keys to remove from the cache on service termination. | ||
| CacheCollector::$lock | protected | property | The lock backend that should be used. | 1 | |
| CacheCollector::$storage | protected | property | Storage for the data itself. | ||
| CacheCollector::$tags | protected | property | A list of tags that are used for the cache entry. | ||
| CacheCollector::clear | public | function | Clears the collected cache entry. | Overrides CacheCollectorInterface::clear | 1 | 
| CacheCollector::delete | public | function | Deletes the element. | Overrides CacheCollectorInterface::delete | |
| CacheCollector::destruct | public | function | Performs destruct operations. | Overrides DestructableInterface::destruct | |
| CacheCollector::get | public | function | Gets value from the cache. | Overrides CacheCollectorInterface::get | 2 | 
| CacheCollector::getCid | protected | function | Gets the cache ID. | 3 | |
| CacheCollector::has | public | function | Returns whether data exists for this key. | Overrides CacheCollectorInterface::has | 1 | 
| CacheCollector::invalidateCache | protected | function | Invalidate the cache. | ||
| CacheCollector::lazyLoadCache | protected | function | Loads the cache if not already done. | 1 | |
| CacheCollector::normalizeLockName | protected | function | Normalizes a cache ID in order to comply with database limitations. | ||
| CacheCollector::persist | protected | function | Flags an offset value to be written to the persistent cache. | ||
| CacheCollector::reset | public | function | Resets the local cache. | Overrides CacheCollectorInterface::reset | 1 | 
| CacheCollector::set | public | function | Implements \Drupal\Core\Cache\CacheCollectorInterface::set(). | Overrides CacheCollectorInterface::set | 1 | 
| CacheCollector::updateCache | protected | function | Writes a value to the persistent cache immediately. | 1 | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
