Skip to content

Commit

Permalink
Added command InvalidateCacheCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
tg666 committed Feb 5, 2024
1 parent 5a28646 commit 9d6157e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace SixtyEightPublishers\ArchitectureBundle\Application\Command;

use SixtyEightPublishers\ArchitectureBundle\Command\CommandInterface;

final class InvalidateCacheCommand implements CommandInterface
{
/**
* @param array<int, string> $keys
* @param array<int, string> $tags
*/
public function __construct(
public readonly array $keys = [],
public readonly array $tags = [],
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace SixtyEightPublishers\ArchitectureBundle\Application\CommandHandler;

use SixtyEightPublishers\ArchitectureBundle\Application\Command\InvalidateCacheCommand;
use SixtyEightPublishers\ArchitectureBundle\Command\CommandHandlerInterface;
use SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheInterface;
use function count;

final class InvalidateCacheCommandHandler implements CommandHandlerInterface
{
public function __construct(
private readonly CacheInterface $cache,
) {}

public function __invoke(InvalidateCacheCommand $command): void
{
foreach ($command->keys as $key) {
$this->cache->deleteItem(
key: $key,
);
}

if (0 < count($command->tags)) {
$this->cache->clean(
tags: $command->tags,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ services:
-
autowired: no
factory: SixtyEightPublishers\ArchitectureBundle\Application\CommandHandler\TransactionalCommandHandler
-
autowired: no
factory: SixtyEightPublishers\ArchitectureBundle\Application\CommandHandler\InvalidateCacheCommandHandler

0 comments on commit 9d6157e

Please sign in to comment.