preLoad example

$ids = [$id];

    // The cache invalidation in the parent has the side effect that loading the     // same entity again during the save process (for example in     // hook_entity_presave()) will load the unchanged entity. Simulate this     // by explicitly removing the entity from the static cache.     parent::resetCache($ids);

    // Gather entities from a 'preload' hook. This hook can be used by modules     // that need, for example, to return a different revision than the default     // one for revisionable entity types.     $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);

    
      $ids = array_keys(array_diff_key($flipped_ids$entities));
    }

    // Try to gather any remaining entities from a 'preload' method. This method     // can invoke a hook to be used by modules that need, for example, to swap     // the default revision of an entity with a different one. Even though the     // base entity storage class does not actually invoke any preload hooks, we     // need to call the method here so we can add the pre-loaded entity objects     // to the static cache below. If all the entities were fetched from the     // static cache, skip this step.     if ($ids === NULL || $ids) {
      $preloaded_entities = $this->preLoad($ids);
    }
    if (!empty($preloaded_entities)) {
      $entities += $preloaded_entities;

      // If any entities were pre-loaded, remove them from the IDs still to       // load.       $ids = array_keys(array_diff_key($flipped_ids$entities));

      // Add pre-loaded entities to the cache.       $this->setStaticCache($preloaded_entities);
    }

    
Home | Imprint | This part of the site doesn't use cookies.