Skip to content

Commit 2b506e3

Browse files
authored
1.6.2 [feature] - implements symfony cache adapter (#3)
* v1.6.2 [feature] implements Symfony cache adapter * Add symfony and psr16 cache tests * Remove deprecated from Redis adpter
1 parent 73f563a commit 2b506e3

6 files changed

Lines changed: 34 additions & 7 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ergebnis/composer-normalize": "^2.29",
2121
"friendsofphp/php-cs-fixer": "^3.13",
2222
"micro/plugin-doctrine": "^1.6",
23-
"micro/plugin-redis": "^1.0",
23+
"micro/plugin-redis": "^1.6",
2424
"phpstan/phpstan": "^1.9",
2525
"phpunit/php-code-coverage": "^9.2",
2626
"phpunit/phpunit": "^9.5",

src/Business/Adapter/Concrete/RedisFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Micro\Component\DependencyInjection\Exception\ServiceNotRegisteredException;
1818
use Micro\Plugin\Cache\Business\Adapter\ConcreteAdapterFactoryInterface;
1919
use Micro\Plugin\Cache\Configuration\Adapter\CachePoolConfigurationInterface;
20-
use Micro\Plugin\Redis\RedisFacadeInterface;
20+
use Micro\Plugin\Redis\Facade\RedisFacadeInterface;
2121
use Psr\Cache\CacheItemPoolInterface;
2222
use Symfony\Component\Cache\Adapter\RedisAdapter;
2323
use Symfony\Component\Cache\Exception\CacheException;

src/Business/Pool/CachePool.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Micro\Plugin\Cache\Business\Adapter\AdapterFactoryInterface;
1717
use Psr\Cache\CacheItemPoolInterface;
18+
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1819
use Symfony\Component\Cache\Adapter\Psr16Adapter;
1920
use Symfony\Component\Cache\Psr16Cache;
2021

@@ -50,4 +51,12 @@ public function getCachePsr6(string $cachePoolName): CacheItemPoolInterface
5051

5152
return $item;
5253
}
54+
55+
public function getCacheSymfony(string $cachePoolName): AbstractAdapter
56+
{
57+
/** @var AbstractAdapter $item */
58+
$item = $this->getCachePsr16($cachePoolName);
59+
60+
return $item;
61+
}
5362
}

src/Business/Pool/CachePoolInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Psr\Cache\CacheException;
1717
use Psr\Cache\CacheItemPoolInterface;
18+
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1819

1920
interface CachePoolInterface
2021
{
@@ -27,4 +28,9 @@ public function getCachePsr16(string $cachePoolName): CacheItemPoolInterface;
2728
* @throws CacheException
2829
*/
2930
public function getCachePsr6(string $cachePoolName): CacheItemPoolInterface;
31+
32+
/**
33+
* @throws CacheException
34+
*/
35+
public function getCacheSymfony(string $cachePoolName): AbstractAdapter;
3036
}

src/Facade/CacheFacade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Micro\Plugin\Cache\Business\Pool\CachePoolFactoryInterface;
1717
use Micro\Plugin\Cache\Business\Pool\CachePoolInterface;
1818
use Psr\Cache\CacheItemPoolInterface;
19+
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1920

2021
class CacheFacade implements CacheFacadeInterface
2122
{
@@ -37,6 +38,11 @@ public function getCachePsr16(string $cachePoolName): CacheItemPoolInterface
3738
return $this->getCachePool()->getCachePsr16($cachePoolName);
3839
}
3940

41+
public function getCacheSymfony(string $cachePoolName): AbstractAdapter
42+
{
43+
return $this->getCachePool()->getCacheSymfony($cachePoolName);
44+
}
45+
4046
protected function getCachePool(): CachePoolInterface
4147
{
4248
if ($this->cachePool) {

tests/Unit/CachePluginConfigurationTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,28 @@ public function testGetPoolConfiguration(array $cfg)
3535
);
3636

3737
$kernel->run();
38-
$cache6 = $kernel->container()->get(CacheFacadeInterface::class)->getCachePsr6('test');
39-
$cache16 = $kernel->container()->get(CacheFacadeInterface::class)->getCachePsr16('test');
38+
$facade = $kernel->container()->get(CacheFacadeInterface::class);
39+
$cache6 = $facade->getCachePsr6('test');
40+
$cache16 = $facade->getCachePsr16('test');
41+
$cacheSf = $facade->getCacheSymfony('test');
4042

4143
$key6 = uniqid();
4244
$key16 = uniqid();
45+
$keySf = uniqid();
4346
$val = new \stdClass();
4447
$val->hello = 'World';
4548

46-
$cached16 = $cache16->get($key16, fn () => $val);
49+
$cached16 = $cache16->getItem($key16);
50+
$cached16->set($val);
51+
$cache16->save($cached16);
4752

48-
$this->assertEquals($val, $cached16);
53+
$this->assertEquals($val, $cache16->getItem($key16)->get());
54+
$this->assertEquals($val, $cached16->get());
55+
$this->assertEquals($val, $cacheSf->get($keySf, fn () => $val));
4956

5057
$cacheItem = $cache6->getItem($key6);
5158
$cacheItem->set($val);
5259
$cache6->save($cacheItem);
53-
5460
$cacheItem = $cache6->getItem($key6);
5561
$cachedValue = $cacheItem->get();
5662

0 commit comments

Comments
 (0)