buildCacheId example

public function loadUnchanged($id) {
    $this->resetCache([$id]);
    return $this->load($id);
  }

  /** * {@inheritdoc} */
  public function resetCache(array $ids = NULL) {
    if ($this->entityType->isStaticallyCacheable() && isset($ids)) {
      foreach ($ids as $id) {
        $this->memoryCache->delete($this->buildCacheId($id));
      }
    }
    else {
      // Call the backend method directly.       $this->memoryCache->invalidateTags([$this->memoryCacheTag]);
    }
  }

  /** * Gets entities from the static cache. * * @param array $ids * If not empty, return entities that match these IDs. * * @return \Drupal\Core\Entity\EntityInterface[] * Array of entities from the entity cache, keyed by entity ID. */

  protected function getFromPersistentCache(array &$ids = NULL) {
    if (!$this->entityType->isPersistentlyCacheable() || empty($ids)) {
      return [];
    }
    $entities = [];
    // Build the list of cache entries to retrieve.     $cid_map = [];
    foreach ($ids as $id) {
      $cid_map[$id] = $this->buildCacheId($id);
    }
    $cids = array_values($cid_map);
    if ($cache = $this->cacheBackend->getMultiple($cids)) {
      // Get the entities that were found in the cache.       foreach ($ids as $index => $id) {
        $cid = $cid_map[$id];
        if (isset($cache[$cid])) {
          $entities[$id] = $cache[$cid]->data;
          unset($ids[$index]);
        }
      }
    }
/** * {@inheritdoc} */
  public function hasData() {
    return (bool) $this->configFactory->listAll($this->getPrefix());
  }

  /** * {@inheritdoc} */
  protected function buildCacheId($id) {
    return parent::buildCacheId($id) . ':' . ($this->overrideFree ? '' : implode(':', $this->configFactory->getCacheKeys()));
  }

  /** * Invokes a hook on behalf of the entity. * * @param $hook * One of 'presave', 'insert', 'update', 'predelete', or 'delete'. * @param $entity * The entity object. */
  protected function invokeHook($hook, EntityInterface $entity) {
    
Home | Imprint | This part of the site doesn't use cookies.