diff --git a/composer.json b/composer.json index 6dae7ed..b24a80a 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "router", "session" ], - "homepage": "https://github.com/php-cache/cache-bundle", + "homepage": "http://www.php-cache.com/en/latest/", "license": "MIT", "authors": [ { @@ -24,15 +24,15 @@ } ], "require": { - "php": "^5.5|^7", + "php": "^5.5|^7.0", "symfony/framework-bundle": "^2.7|^3.0", - "cache/taggable-cache": "^0.3", + "cache/taggable-cache": "^0.4", "cache/session-handler": "^0.1" }, "require-dev": { "phpunit/phpunit": "^5.1|^4.0", "cache/psr-6-doctrine-bridge": "^2.0", - "cache/array-adapter": "@stable" + "cache/array-adapter": "^0.4" }, "suggest": { "cache/adapter-bundle": "To register PSR-6 compliant cache implementations as services.", diff --git a/src/Cache/FixedTaggingCachePool.php b/src/Cache/FixedTaggingCachePool.php index 8d5c5de..10c1a11 100644 --- a/src/Cache/FixedTaggingCachePool.php +++ b/src/Cache/FixedTaggingCachePool.php @@ -11,6 +11,7 @@ namespace Cache\CacheBundle\Cache; +use Cache\Taggable\TaggableItemInterface; use Cache\Taggable\TaggablePoolInterface; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; @@ -48,7 +49,7 @@ public function __construct(TaggablePoolInterface $cache, array $tags) */ public function getItem($key) { - return $this->cache->getItem($key, $this->tags); + return $this->cache->getItem($key); } /** @@ -56,7 +57,7 @@ public function getItem($key) */ public function getItems(array $keys = []) { - return $this->cache->getItems($keys, $this->tags); + return $this->cache->getItems($keys); } /** @@ -64,7 +65,7 @@ public function getItems(array $keys = []) */ public function hasItem($key) { - return $this->cache->hasItem($key, $this->tags); + return $this->cache->hasItem($key); } /** @@ -72,7 +73,7 @@ public function hasItem($key) */ public function clear() { - return $this->cache->clear($this->tags); + return $this->cache->clear(); } /** @@ -80,7 +81,7 @@ public function clear() */ public function deleteItem($key) { - return $this->cache->deleteItem($key, $this->tags); + return $this->cache->deleteItem($key); } /** @@ -88,7 +89,7 @@ public function deleteItem($key) */ public function deleteItems(array $keys) { - return $this->cache->deleteItems($keys, $this->tags); + return $this->cache->deleteItems($keys); } /** @@ -96,6 +97,8 @@ public function deleteItems(array $keys) */ public function save(CacheItemInterface $item) { + $this->addTags($item); + return $this->cache->save($item); } @@ -104,9 +107,21 @@ public function save(CacheItemInterface $item) */ public function saveDeferred(CacheItemInterface $item) { + $this->addTags($item); + return $this->cache->saveDeferred($item); } + /** + * @param TaggableItemInterface $item + */ + private function addTags(TaggableItemInterface $item) + { + foreach ($this->tags as $tag) { + $item->addTag($tag); + } + } + /** * {@inheritdoc} */ diff --git a/src/Cache/RecordingCachePool.php b/src/Cache/RecordingCachePool.php index b94d9a9..307a32e 100644 --- a/src/Cache/RecordingCachePool.php +++ b/src/Cache/RecordingCachePool.php @@ -67,11 +67,11 @@ private function timeCall($name, array $arguments = null) return $object; } - public function getItem($key, array $tags = []) + public function getItem($key) { - $call = $this->timeCall(__FUNCTION__, [$key, $tags]); - $result = $call->result; - $call->isHit = $result->isHit(); + $call = $this->timeCall(__FUNCTION__, [$key]); + $result = $call->result; + $call->isHit = $result->isHit(); // Display the result in a good way depending on the data type if ($call->isHit) { @@ -85,17 +85,17 @@ public function getItem($key, array $tags = []) return $result; } - public function hasItem($key, array $tags = []) + public function hasItem($key) { - $call = $this->timeCall(__FUNCTION__, [$key, $tags]); + $call = $this->timeCall(__FUNCTION__, [$key]); $this->addCall($call); return $call->result; } - public function deleteItem($key, array $tags = []) + public function deleteItem($key) { - $call = $this->timeCall(__FUNCTION__, [$key, $tags]); + $call = $this->timeCall(__FUNCTION__, [$key]); $this->addCall($call); return $call->result; @@ -125,9 +125,9 @@ public function saveDeferred(CacheItemInterface $item) return $call->result; } - public function getItems(array $keys = [], array $tags = []) + public function getItems(array $keys = []) { - $call = $this->timeCall(__FUNCTION__, [$keys, $tags]); + $call = $this->timeCall(__FUNCTION__, [$keys]); $result = $call->result; $call->result = sprintf('', gettype($result)); $this->addCall($call); @@ -135,17 +135,25 @@ public function getItems(array $keys = [], array $tags = []) return $result; } - public function clear(array $tags = []) + public function clear() + { + $call = $this->timeCall(__FUNCTION__, []); + $this->addCall($call); + + return $call->result; + } + + public function clearTags(array $tags) { - $call = $this->timeCall(__FUNCTION__, [$tags]); + $call = $this->timeCall(__FUNCTION__, [$tags]); $this->addCall($call); return $call->result; } - public function deleteItems(array $keys, array $tags = []) + public function deleteItems(array $keys) { - $call = $this->timeCall(__FUNCTION__, [$keys, $tags]); + $call = $this->timeCall(__FUNCTION__, [$keys]); $this->addCall($call); return $call->result; @@ -153,7 +161,7 @@ public function deleteItems(array $keys, array $tags = []) public function commit() { - $call = $this->timeCall(__FUNCTION__); + $call = $this->timeCall(__FUNCTION__); $this->addCall($call); return $call->result; diff --git a/src/Command/CacheFlushCommand.php b/src/Command/CacheFlushCommand.php index 24ebfcf..4f85655 100644 --- a/src/Command/CacheFlushCommand.php +++ b/src/Command/CacheFlushCommand.php @@ -123,7 +123,7 @@ private function clearTypedCacheFromService($type, $serviceId) /** @type \Psr\Cache\CacheItemPoolInterface $service */ $service = $this->getContainer()->get($serviceId); if ($service instanceof TaggablePoolInterface) { - return $service->clear([$type]); + return $service->clearTags([$type]); } else { return $service->clear(); } diff --git a/src/Routing/CachingRouter.php b/src/Routing/CachingRouter.php index 33897d1..6a631a2 100644 --- a/src/Routing/CachingRouter.php +++ b/src/Routing/CachingRouter.php @@ -11,7 +11,7 @@ namespace Cache\CacheBundle\Routing; -use Cache\Taggable\TaggablePoolInterface; +use Cache\Taggable\TaggableItemInterface; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouterInterface; @@ -163,10 +163,10 @@ public function __call($method, $args) */ private function getCacheItemFromKey($key, $tag) { - if ($this->cache instanceof TaggablePoolInterface) { - $item = $this->cache->getItem($key, ['router', $tag]); - } else { - $item = $this->cache->getItem($key); + $item = $this->cache->getItem($key); + + if ($item instanceof TaggableItemInterface) { + $item->setTags(['router', $tag]); } return $item; diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index c2881c2..f4b3605 100755 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -18,9 +18,6 @@ */ class ContainerTest extends TestCase { - /** - * - */ public function testContainer() { //$container = $this->createContainer(); diff --git a/tests/DependencyInjection/CacheExtensionTest.php b/tests/DependencyInjection/CacheExtensionTest.php index 18625bb..e88aff0 100755 --- a/tests/DependencyInjection/CacheExtensionTest.php +++ b/tests/DependencyInjection/CacheExtensionTest.php @@ -20,9 +20,6 @@ */ class CacheExtensionTest extends TestCase { - /** - * - */ public function testRouterBuilder() { $container = $this->createContainerFromFile('router');