Skip to content

Commit

Permalink
create a dedicated cache pool for files
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-sainthillier committed Dec 2, 2023
1 parent cafc729 commit ebb6745
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions config/packages/cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ framework:
#app: cache.adapter.apcu

# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: null
pools:
files_cache_pool:
adapter: cache.adapter.filesystem
6 changes: 3 additions & 3 deletions src/Storage/DataStorageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class DataStorageHandler
{
public function __construct(
private readonly CacheInterface $cache,
private readonly CacheInterface $filesCachePool,
) {
}

Expand All @@ -27,7 +27,7 @@ public function store(array $data): string
$cacheKey = $this->getCacheKey($id);

$this
->cache
->filesCachePool
->get($cacheKey, function (ItemInterface $item) use ($data) {
$item->expiresAfter(3600);

Expand All @@ -44,7 +44,7 @@ public function get(string $id): array
{
$cacheKey = $this->getCacheKey($id);

return $this->cache->get($cacheKey, fn () => throw new DataNotFoundException(sprintf('No data found for "%s"', $cacheKey)));
return $this->filesCachePool->get($cacheKey, fn () => throw new DataNotFoundException(sprintf('No data found for "%s"', $cacheKey)));
}

private function getCacheKey(string $id): string
Expand Down

0 comments on commit ebb6745

Please sign in to comment.