-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added service of type `CacheRegistryInterface` - added property `cacheName` to the `CacheMetadata` and `InvalidateCacheCommand` classes - added `memory` cache into the DIC
- Loading branch information
Showing
9 changed files
with
127 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletions
23
...hitectureBundle/Bridge/Nette/DI/definitions/architecture_bundle/infrastructure.cache.neon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
services: | ||
infrastructure.cache_registry: | ||
autowired: SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheRegistryInterface | ||
type: SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheRegistryInterface | ||
factory: @extension.infrastructure.cache_registry.default | ||
|
||
infrastructure.cache_registry.default: | ||
autowired: no | ||
factory: SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheRegistry( | ||
cacheServices: [ | ||
memory: @extension.infrastructure.cache.memory | ||
] | ||
) | ||
|
||
infrastructure.cache: | ||
autowired: SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheInterface | ||
type: SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheInterface | ||
factory: @extension.infrastructure.cache.nette | ||
factory: @extension.infrastructure.cache.default | ||
|
||
infrastructure.cache.nette: | ||
infrastructure.cache.default: | ||
autowired: no | ||
factory: SixtyEightPublishers\ArchitectureBundle\Infrastructure\NetteCache\NetteCache | ||
|
||
infrastructure.cache.memory: | ||
autowired: no | ||
factory: SixtyEightPublishers\ArchitectureBundle\Infrastructure\NetteCache\NetteCache( | ||
storage: Nette\Caching\Storages\MemoryStorage(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/ArchitectureBundle/Bridge/Symfony/Messenger/Stamp/CacheStamp.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SixtyEightPublishers\ArchitectureBundle\Bridge\Symfony\Messenger\Stamp; | ||
|
||
use SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache\CacheMetadata; | ||
use Symfony\Component\Messenger\Stamp\StampInterface; | ||
|
||
final class CacheStamp implements StampInterface | ||
{ | ||
public function __construct( | ||
public readonly CacheMetadata $metadata, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/ArchitectureBundle/Infrastructure/Cache/CacheRegistry.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache; | ||
|
||
final class CacheRegistry implements CacheRegistryInterface | ||
{ | ||
/** | ||
* @param array<string, CacheInterface> $cacheServices | ||
*/ | ||
public function __construct( | ||
private readonly CacheInterface $defaultCacheService, | ||
private array $cacheServices = [], | ||
) {} | ||
|
||
public function addCacheService(string $name, CacheInterface $cache): void | ||
{ | ||
$this->cacheServices[$name] = $cache; | ||
} | ||
|
||
public function getCache(?string $name): CacheInterface | ||
{ | ||
if (null === $name) { | ||
return $this->defaultCacheService; | ||
} | ||
|
||
if (!isset($this->cacheServices[$name])) { | ||
throw MissingCacheServiceException::create( | ||
name: $name, | ||
); | ||
} | ||
|
||
return $this->cacheServices[$name]; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/ArchitectureBundle/Infrastructure/Cache/CacheRegistryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache; | ||
|
||
interface CacheRegistryInterface | ||
{ | ||
/** | ||
* @throws MissingCacheServiceException | ||
*/ | ||
public function getCache(?string $name): CacheInterface; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/ArchitectureBundle/Infrastructure/Cache/MissingCacheServiceException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SixtyEightPublishers\ArchitectureBundle\Infrastructure\Cache; | ||
|
||
use InvalidArgumentException; | ||
use function sprintf; | ||
|
||
final class MissingCacheServiceException extends InvalidArgumentException | ||
{ | ||
public static function create(string $name): self | ||
{ | ||
return new self( | ||
message: sprintf( | ||
'Cache service "%s" is missing.', | ||
$name, | ||
), | ||
); | ||
} | ||
} |