Skip to content

Commit

Permalink
Improve GraphQL caching for large queries
Browse files Browse the repository at this point in the history
Pimcore limits caching to a maximum of 50 items per request. For large
GraphQL queries, this limit can easily be exceeded because every object
loaded during query resolution is added to the cache queue with priority 0.
When the queue is truncated, only the top 50 items (by priority) are
retained.

This commit increases the priority of the final GraphQL query result,
ensuring this is more likely to be cached despite the 50-item limit.
  • Loading branch information
gajdusek committed Jan 15, 2025
1 parent 2c120fd commit d219306
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Service/OutputCacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ protected function loadFromCache($key)
*/
protected function saveToCache($key, $item, $tags = []): void
{
\Pimcore\Cache::save($item, $key, $tags, $this->lifetime);
# Increase priority to 1 to make it less likely this cache item is evicted from the
# queue before actually being written
\Pimcore\Cache::save($item, $key, $tags, $this->lifetime, 1);
}

private function computeKey(Request $request): string
Expand Down

0 comments on commit d219306

Please sign in to comment.