Skip to content

Commit

Permalink
update cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Oct 13, 2023
1 parent 235a77f commit e9b8a36
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

final class Psr16AggregateRootRegistryFactory implements AggregateRootRegistryFactory
{
private const CACHE_KEY = 'aggregate_root_registry';

public function __construct(
private readonly AggregateRootRegistryFactory $aggregateRootRegistryFactory,
private readonly CacheInterface $cache,
Expand All @@ -18,15 +20,15 @@ public function __construct(
public function create(array $paths): AggregateRootRegistry
{
/** @var ?AggregateRootRegistry $registry */
$registry = $this->cache->get('aggregate_roots');
$registry = $this->cache->get(self::CACHE_KEY);

if ($registry !== null) {
return $registry;
}

$registry = $this->aggregateRootRegistryFactory->create($paths);

$this->cache->set('aggregate_roots', $registry);
$this->cache->set(self::CACHE_KEY, $registry);

return $registry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

final class Psr6AggregateRootRegistryFactory implements AggregateRootRegistryFactory
{
private const CACHE_KEY = 'aggregate_root_registry';

public function __construct(
private readonly AggregateRootRegistryFactory $aggregateRootRegistryFactory,
private readonly CacheItemPoolInterface $cache,
Expand All @@ -19,7 +21,7 @@ public function __construct(
/** @param list<string> $paths */
public function create(array $paths): AggregateRootRegistry
{
$item = $this->cache->getItem('aggregate_roots');
$item = $this->cache->getItem(self::CACHE_KEY);

if ($item->isHit()) {
$data = $item->get();
Expand Down
6 changes: 4 additions & 2 deletions src/Metadata/Event/Psr16EventRegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

final class Psr16EventRegistryFactory implements EventRegistryFactory
{
private const CACHE_KEY = 'event_registry';

public function __construct(
private readonly EventRegistryFactory $eventRegistryFactory,
private readonly CacheInterface $cache,
Expand All @@ -18,15 +20,15 @@ public function __construct(
public function create(array $paths): EventRegistry
{
/** @var ?EventRegistry $registry */
$registry = $this->cache->get('events');
$registry = $this->cache->get(self::CACHE_KEY);

if ($registry !== null) {
return $registry;
}

$registry = $this->eventRegistryFactory->create($paths);

$this->cache->set('events', $registry);
$this->cache->set(self::CACHE_KEY, $registry);

return $registry;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Metadata/Event/Psr6EventRegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

final class Psr6EventRegistryFactory implements EventRegistryFactory
{
private const CACHE_KEY = 'event_registry';

public function __construct(
private readonly EventRegistryFactory $eventRegistryFactory,
private readonly CacheItemPoolInterface $cache,
Expand All @@ -19,7 +21,7 @@ public function __construct(
/** @param list<string> $paths */
public function create(array $paths): EventRegistry
{
$item = $this->cache->getItem('events');
$item = $this->cache->getItem(self::CACHE_KEY);

if ($item->isHit()) {
$data = $item->get();
Expand Down

0 comments on commit e9b8a36

Please sign in to comment.