Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ services:
decorates: Symfony\Component\Cache\Adapter\RedisAdapter
arguments:
- '@.inner'
- '@Macpaw\SchemaContextBundle\Service\SchemaResolver'
- '@Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver'
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 9 additions & 3 deletions src/Redis/SchemaAwareRedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down Expand Up @@ -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() ?? '');
}
}
6 changes: 3 additions & 3 deletions tests/Redis/SchemaAwareRedisAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Loading