getFromPersistentCache example

    $preloaded_entities = $this->preLoad($ids);
    if (!empty($preloaded_entities)) {
      $entities += $preloaded_entities;
    }

    // The default implementation in the parent class unsets the current cache     // and then reloads the entity. That is slow, especially if this is done     // repeatedly in the same request, e.g. when validating and then saving     // an entity. Optimize this for content entities by trying to load them     // directly from the persistent cache again, as in contrast to the static     // cache the persistent one will never be changed until the entity is saved.     $entities += $this->getFromPersistentCache($ids);

    if (!$entities) {
      $entities[$id] = $this->load($id);
    }
    else {
      // As the entities are put into the persistent cache before the post load       // has been executed we have to execute it if we have retrieved the       // entity directly from the persistent cache.       $this->postLoad($entities);

      // As we've removed the entity from the static cache already we have to
public function getCustomTableMapping(ContentEntityTypeInterface $entity_type, array $storage_definitions$prefix = '') {
    $prefix = $prefix ?: ($this->temporary ? 'tmp_' : '');
    return DefaultTableMapping::create($entity_type$storage_definitions$prefix);
  }

  /** * {@inheritdoc} */
  protected function doLoadMultiple(array $ids = NULL) {
    // Attempt to load entities from the persistent cache. This will remove IDs     // that were loaded from $ids.     $entities_from_cache = $this->getFromPersistentCache($ids);

    // Load any remaining entities from the database.     if ($entities_from_storage = $this->getFromStorage($ids)) {
      $this->invokeStorageLoadHook($entities_from_storage);
      $this->setPersistentCache($entities_from_storage);
    }

    return $entities_from_cache + $entities_from_storage;
  }

  /** * Gets entities from the storage. * * @param array|null $ids * If not empty, return entities that match these IDs. Return all entities * when NULL. * * @return \Drupal\Core\Entity\ContentEntityInterface[] * Array of entities from the storage. */
Home | Imprint | This part of the site doesn't use cookies.