Skip to content

Commit e311c72

Browse files
committed
Adding function moveTagsToPrevious
1 parent d89223e commit e311c72

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

EncryptedCachePool.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Cache\Encryption;
1313

14+
use Cache\Adapter\Common\PhpCacheItem;
1415
use Cache\Adapter\Common\PhpCachePool;
1516
use Cache\TagInterop\TaggableCacheItemInterface;
1617
use Cache\Taggable\TaggablePSR6PoolAdapter;
@@ -25,10 +26,10 @@
2526
*
2627
* @author Daniel Bannert <[email protected]>
2728
*/
28-
class EncryptedCachePool implements TaggableCacheItemPoolInterface
29+
class EncryptedCachePool implements PhpCachePool
2930
{
3031
/**
31-
* @type TaggableCacheItemInterface
32+
* @type PhpCachePool
3233
*/
3334
private $cachePool;
3435

@@ -38,12 +39,12 @@ class EncryptedCachePool implements TaggableCacheItemPoolInterface
3839
private $key;
3940

4041
/**
41-
* @param CacheItemPoolInterface $cachePool
42-
* @param Key $key
42+
* @param PhpCachePool $cachePool
43+
* @param Key $key
4344
*/
44-
public function __construct(CacheItemPoolInterface $cachePool, Key $key)
45+
public function __construct(PhpCachePool $cachePool, Key $key)
4546
{
46-
$this->cachePool = TaggablePSR6PoolAdapter::makeTaggable($cachePool);
47+
$this->cachePool = $cachePool;
4748
$this->key = $key;
4849
}
4950

@@ -66,7 +67,7 @@ public function getItem($key)
6667
*/
6768
public function getItems(array $keys = [])
6869
{
69-
return array_map(function (CacheItemInterface $inner) {
70+
return array_map(function (PhpCacheItem $inner) {
7071
if (!($inner instanceof EncryptedItemDecorator)) {
7172
return new EncryptedItemDecorator($inner, $this->key);
7273
}
@@ -112,6 +113,10 @@ public function deleteItems(array $keys)
112113
*/
113114
public function save(CacheItemInterface $item)
114115
{
116+
if (!$item instanceof PhpCacheItem) {
117+
throw new InvalidArgumentException('Cache items are not transferable between pools. Item MUST implement PhpCacheItem.');
118+
}
119+
115120
if (!($item instanceof EncryptedItemDecorator)) {
116121
$item = new EncryptedItemDecorator($item, $this->key);
117122
}
@@ -124,6 +129,10 @@ public function save(CacheItemInterface $item)
124129
*/
125130
public function saveDeferred(CacheItemInterface $item)
126131
{
132+
if (!$item instanceof PhpCacheItem) {
133+
throw new InvalidArgumentException('Cache items are not transferable between pools. Item MUST implement PhpCacheItem.');
134+
}
135+
127136
if (!($item instanceof EncryptedItemDecorator)) {
128137
$item = new EncryptedItemDecorator($item, $this->key);
129138
}

EncryptedItemDecorator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author Daniel Bannert <[email protected]>
2424
*/
25-
class EncryptedItemDecorator implements TaggableCacheItemInterface
25+
class EncryptedItemDecorator implements PhpCacheItem
2626
{
2727
/**
2828
* @type PhpCacheItem
@@ -175,4 +175,14 @@ private function transform(array $item)
175175

176176
return $value;
177177
}
178+
179+
/**
180+
* @internal This function should never be used and considered private.
181+
*
182+
* Move tags from $tags to $prevTags
183+
*/
184+
public function moveTagsToPrevious()
185+
{
186+
$this->cacheItem->moveTagsToPrevious();
187+
}
178188
}

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"require": {
3131
"php": "^5.5 || ^7.0",
3232
"defuse/php-encryption": "^2.0",
33-
"cache/taggable-cache": "^0.5",
34-
"cache/tag-interop": "^1.0",
33+
"cache/adapter-common": "^0.4",
3534
"psr/cache": "^1.0"
3635
},
3736
"require-dev": {

0 commit comments

Comments
 (0)