final class DeveloperCache in Apigee Edge 8
Default developer cache implementation.
Generates additional cache entries for developers by using their email addresses as cache ids. This way developers can be served from cache both by their developer id (UUID) an email address.
Hierarchy
- class \Drupal\apigee_edge\Entity\Controller\Cache\EntityCache implements EntityCacheInterface
- class \Drupal\apigee_edge\Entity\Controller\Cache\DeveloperCache implements EntityCacheInterface
Expanded class hierarchy of DeveloperCache
1 string reference to 'DeveloperCache'
1 service uses DeveloperCache
File
- src/
Entity/ Controller/ Cache/ DeveloperCache.php, line 33
Namespace
Drupal\apigee_edge\Entity\Controller\CacheView source
final class DeveloperCache extends EntityCache implements EntityCacheInterface {
/**
* An internal cache for developer ids and emails.
*
* Associative array, keys are developer ids and values are email addresses.
*
* @var array
*/
private $developerIdEmailMap = [];
/**
* DeveloperCache constructor.
*
* @param \Drupal\apigee_edge\MemoryCacheFactoryInterface $memory_cache_factory
* The memory cache factory service.
* @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface $entity_id_cache
* The developer entity id cache.
*/
public function __construct(MemoryCacheFactoryInterface $memory_cache_factory, EntityIdCacheInterface $entity_id_cache) {
parent::__construct($memory_cache_factory, $entity_id_cache, 'developer');
}
/**
* {@inheritdoc}
*/
protected function prepareCacheItem(EntityInterface $entity) : array {
/** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface $entity */
$item = parent::prepareCacheItem($entity);
// Add developer's email as tag to generated cache items by the parent
// class.
foreach ($item as $cid => $developer) {
$item[$cid]['tags'][] = $entity
->getEmail();
}
$this->developerIdEmailMap[$entity
->getDeveloperId()] = $entity
->getEmail();
return $item;
}
/**
* {@inheritdoc}
*/
protected function doSaveEntities(array $entities) : void {
parent::doSaveEntities($entities);
$items = [];
foreach ($entities as $entity) {
// Add new cache item that uses developer's email address as a cid instead
// of developer's id (UUID).
$items[$entity
->getEmail()] = [
'data' => $entity,
'tags' => [
$entity
->getDeveloperId(),
$entity
->getEmail(),
],
];
}
$this->cacheBackend
->setMultiple($items);
}
/**
* {@inheritdoc}
*/
protected function doRemoveEntities(array $ids) : void {
if (!empty($ids)) {
// If ids are developer ids (UUIDs).
$dev_id_email_address_matches = array_intersect_key($this->developerIdEmailMap, array_flip($ids));
// If ids are email addresses.
$dev_id_email_address_matches += array_flip(array_intersect_key(array_flip($this->developerIdEmailMap), array_flip($ids)));
// Because all cached entries tagged with email address and developer
// id (UUID) this should invalidate everything that is needed in this
// cache...
$this->cacheBackend
->invalidateTags($ids);
// ... although if $ids are developer ids (UUIDs) then the entity id cache
// does not get invalidated properly in parent.
$this->entityIdCache
->removeIds($dev_id_email_address_matches);
// Remove removed items from the internal cache.
$this->developerIdEmailMap = array_diff_key($this->developerIdEmailMap, $dev_id_email_address_matches);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeveloperCache:: |
private | property | An internal cache for developer ids and emails. | |
DeveloperCache:: |
protected | function |
Allows to perform additional tasks after entities got deleted from cache. Overrides EntityCache:: |
|
DeveloperCache:: |
protected | function |
Allows to perform additional tasks after entities got saved to cache. Overrides EntityCache:: |
|
DeveloperCache:: |
protected | function |
Generates cache items for an entity. Overrides EntityCache:: |
|
DeveloperCache:: |
public | function |
DeveloperCache constructor. Overrides EntityCache:: |
|
EntityCache:: |
private | property | Indicates whether all entities in the cache or not. | |
EntityCache:: |
protected | property | The memory cache backend used by this cache. | |
EntityCache:: |
private | property | Array of entity ids stored in the cache. | |
EntityCache:: |
protected | property | The entity id cache related to this entity type. | |
EntityCache:: |
final public | function |
Changes whether all entities in the cache or not. Overrides EntityCacheInterface:: |
|
EntityCache:: |
final public | function |
Returns entities from the cache. Overrides EntityCacheInterface:: |
|
EntityCache:: |
final public | function |
Returns an entity from the cache by its id. Overrides EntityCacheInterface:: |
|
EntityCache:: |
final public | function |
Returns whether all entities in cache or not. Overrides EntityCacheInterface:: |
|
EntityCache:: |
final public | function |
Removes entities from the cache by their ids. Overrides EntityCacheInterface:: |
|
EntityCache:: |
final public | function |
Saves entities to the cache. Overrides EntityCacheInterface:: |
|
EntityCache:: |
public | function | Prevents data stored in entity cache from being serialized. |