class EntityIdCache in Apigee Edge 8
Base definition of the entity id cache service used by controllers.
See the interface definition for more details.
Always create a dedicated instance from this for an entity type!
@internal
Hierarchy
- class \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCache implements EntityIdCacheInterface
Expanded class hierarchy of EntityIdCache
1 string reference to 'EntityIdCache'
1 service uses EntityIdCache
File
- src/
Entity/ Controller/ Cache/ EntityIdCache.php, line 34
Namespace
Drupal\apigee_edge\Entity\Controller\CacheView source
class EntityIdCache implements EntityIdCacheInterface {
/**
* Stored entity ids.
*
* As an associative array where keys and values as the same.
*
* @var string[]
*/
private $ids = [];
/**
* Indicates whether all entity ids in cache all or not.
*
* @var bool
*/
private $allIdsInCache = FALSE;
/**
* {@inheritdoc}
*/
public final function saveIds(array $ids) : void {
// Store entity ids in an associative array because it is easier to work
// with them.
$this->ids += array_combine($ids, $ids);
}
/**
* Allows to perform additional tasks after entity ids got saved to cache.
*
* @param array $ids
* Array of entity ids.
*/
protected function doSaveIds(array $ids) {
}
/**
* {@inheritdoc}
*/
public final function saveEntities(array $entities) : void {
$ids = array_map(function (EntityInterface $entity) {
return $this
->getEntityId($entity);
}, $entities);
$this
->saveIds($ids);
}
/**
* {@inheritdoc}
*/
public final function removeIds(array $ids) : void {
$this->ids = array_diff($this->ids, $ids);
// If ids is empty now, reset the state. Cache can be marked as "complete"
// still by calling the setter method if needed.
if (empty($this->ids)) {
$this->allIdsInCache = FALSE;
}
$this
->doRemoveIds($ids);
}
/**
* Allows to perform additional tasks after entity ids got deleted from cache.
*
* @param array $ids
* Array of entity ids.
*/
protected function doRemoveIds(array $ids) {
}
/**
* {@inheritdoc}
*/
public final function getIds() : array {
// We return a non-associative array because this is what getEntityIds()
// returns.
return array_values($this->ids);
}
/**
* {@inheritdoc}
*/
public final function allIdsInCache(bool $all_ids_in_cache) : void {
$this->allIdsInCache = $all_ids_in_cache;
}
/**
* {@inheritdoc}
*/
public final function isAllIdsInCache() : bool {
return $this->allIdsInCache;
}
/**
* Returns the unique id of an entity that getEntityIds() returns as well.
*
* @param \Apigee\Edge\Entity\EntityInterface $entity
* Entity object.
*
* @return string
* Unique id from the entity that getEntityIds() returns as well.
*/
protected function getEntityId(EntityInterface $entity) : string {
return $entity
->id();
}
/**
* Prevents data stored in entity id cache from being serialized.
*/
public function __sleep() {
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityIdCache:: |
private | property | Indicates whether all entity ids in cache all or not. | |
EntityIdCache:: |
private | property | Stored entity ids. | |
EntityIdCache:: |
final public | function |
Changes whether all ids in the cache or not. Overrides EntityIdCacheInterface:: |
|
EntityIdCache:: |
protected | function | Allows to perform additional tasks after entity ids got deleted from cache. | |
EntityIdCache:: |
protected | function | Allows to perform additional tasks after entity ids got saved to cache. | |
EntityIdCache:: |
protected | function | Returns the unique id of an entity that getEntityIds() returns as well. | 2 |
EntityIdCache:: |
final public | function |
Returns cached ids. Overrides EntityIdCacheInterface:: |
|
EntityIdCache:: |
final public | function |
Returns whether all entity ids in cache or not. Overrides EntityIdCacheInterface:: |
|
EntityIdCache:: |
final public | function |
Removes ids from the cache. Overrides EntityIdCacheInterface:: |
|
EntityIdCache:: |
final public | function |
Adds entities to the cache. Overrides EntityIdCacheInterface:: |
|
EntityIdCache:: |
final public | function |
Adds entity ids to the cache. Overrides EntityIdCacheInterface:: |
|
EntityIdCache:: |
public | function | Prevents data stored in entity id cache from being serialized. |