setStaticCache example

    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);
    }

    // Load any remaining entities from the database. This is the case if $ids     // is set to NULL (so we load all entities) or if there are any IDs left to     // load.     if ($ids === NULL || $ids) {
      $queried_entities = $this->doLoadMultiple($ids);
    }

    // Pass all entities loaded from the database through $this->postLoad(),     // which attaches fields (if supported by the entity type) and calls the
$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       // put the loaded unchanged entity there to simulate the behavior of the       // parent.       $this->setStaticCache($entities);
    }

    return $entities[$id];
  }

  /** * Resets the entity cache. * * Content entities have both an in-memory static cache and a persistent * cache. Use this method to clear all caches. To clear just the in-memory * cache, use the 'entity.memory_cache' service. * * @param array $ids * (optional) If specified, the cache is reset for the entities with the * given ids only. */
Home | Imprint | This part of the site doesn't use cookies.