diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7aab1b6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 MacPaw Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 4cb52e0..28b75ad 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ services: decorates: Symfony\Component\Cache\Adapter\RedisAdapter arguments: - '@.inner' - - '@Macpaw\SchemaContextBundle\Service\SchemaResolver' + - '@Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver' ``` ## Usage diff --git a/composer.json b/composer.json index 74cd537..b44296d 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require": { "php": ">=8.3", - "macpaw/schema-context-bundle": "^1.0", + "macpaw/schema-context-bundle": "^1.1", "symfony/cache": "^6.4|^7.0" }, "require-dev": { diff --git a/src/Redis/SchemaAwareRedisAdapter.php b/src/Redis/SchemaAwareRedisAdapter.php index cc1ca0e..e8242e5 100644 --- a/src/Redis/SchemaAwareRedisAdapter.php +++ b/src/Redis/SchemaAwareRedisAdapter.php @@ -4,18 +4,19 @@ namespace Macpaw\RedisSchemaBundle\Redis; -use Macpaw\SchemaContextBundle\Service\SchemaResolver; +use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver; use Psr\Cache\CacheItemInterface; use Symfony\Component\Cache\Adapter\RedisAdapter; use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\Adapter\AdapterInterface; +use Symfony\Component\Cache\ResettableInterface; use Symfony\Contracts\Cache\CacheInterface; -class SchemaAwareRedisAdapter implements AdapterInterface, CacheInterface +class SchemaAwareRedisAdapter implements AdapterInterface, CacheInterface, ResettableInterface { public function __construct( private readonly RedisAdapter $decorated, - private readonly SchemaResolver $resolver, + private readonly BaggageSchemaResolver $resolver, ) { } @@ -94,4 +95,9 @@ public function delete(string $key): bool { return $this->decorated->delete($this->prefixKey($key)); } + + public function reset(): void + { + $this->decorated->clear($this->resolver->getSchema() ?? ''); + } } diff --git a/tests/Redis/SchemaAwareRedisAdapterTest.php b/tests/Redis/SchemaAwareRedisAdapterTest.php index 2d7d7ae..8b0bf50 100644 --- a/tests/Redis/SchemaAwareRedisAdapterTest.php +++ b/tests/Redis/SchemaAwareRedisAdapterTest.php @@ -5,7 +5,7 @@ namespace Macpaw\RedisSchemaBundle\Tests\Redis; use Macpaw\RedisSchemaBundle\Redis\SchemaAwareRedisAdapter; -use Macpaw\SchemaContextBundle\Service\SchemaResolver; +use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\RedisAdapter; @@ -16,13 +16,13 @@ class SchemaAwareRedisAdapterTest extends TestCase { private RedisAdapter&CacheInterface&MockObject $decorated; - private SchemaResolver $resolver; + private BaggageSchemaResolver $resolver; private SchemaAwareRedisAdapter $adapter; protected function setUp(): void { $this->decorated = $this->createMock(RedisAdapter::class); - $this->resolver = $this->createMock(SchemaResolver::class); + $this->resolver = $this->createMock(BaggageSchemaResolver::class); $this->resolver->method('getSchema')->willReturn('test_schema'); $this->adapter = new SchemaAwareRedisAdapter($this->decorated, $this->resolver);