Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/Entity/Storage/EdgeEntityStorageBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,23 @@ protected function invokeStorageLoadHook(array &$entities) {
* Array of entities from the persistent cache.
*/
protected function getFromPersistentCache(?array &$ids = NULL) {
if (!$this->entityType->isPersistentlyCacheable() || empty($ids)) {

if ($this->cacheExpiration === 0 || !$this->entityType->isPersistentlyCacheable()) {
return [];
}

if ($ids === NULL) {
$all_ids_cid = 'all_ids:' . $this->entityTypeId;
// Try to load our "master ID list" from the cache.
if ($cache = $this->cacheBackend->get($all_ids_cid)) {
// We found the list! Set $ids to this list.
$ids = $cache->data;
}
// If we did NOT find the list, $ids remains NULL. The code
// will proceed as normal, hit the API, and our modified
// setPersistentCache() will create the list for next time.
}
if (empty($ids)) {
return [];
}
$entities = [];
Expand Down Expand Up @@ -412,6 +428,12 @@ protected function setPersistentCache(array $entities) {
return;
}

if (!empty($entities)) {
// Get all entity IDs.
$all_entity_ids = array_keys($entities);
$entity_count = count($all_entity_ids);
}

while (!empty($entities)) {
$cache_items = [];
foreach (array_splice($entities, 0, $this->cacheInsertChunkSize) as $id => $entity) {
Expand All @@ -424,6 +446,22 @@ protected function setPersistentCache(array $entities) {

$this->cacheBackend->setMultiple($cache_items);
}

// After all chunks are saved, save the master ID list.
// We only do this if we actually processed entities from the API.
if ($entity_count > 0) {
$all_ids_cid = 'all_ids:' . $this->entityTypeId;
// Use the main entity type tag so this item is cleared when
// the rest of the entity cache is cleared.
$all_ids_tags = [$this->entityTypeId . ':values'];

$this->cacheBackend->set(
$all_ids_cid,
$all_entity_ids,
$this->getPersistentCacheExpiration(),
$all_ids_tags
);
}
}

/**
Expand Down