From 22c95f8067a4c6696faf5c6de6104d060a44b2db Mon Sep 17 00:00:00 2001 From: Alexandru Bumbacea Date: Thu, 13 Oct 2016 11:50:49 +0300 Subject: [PATCH] fix empty cache issue in interceptor (#4) * fix empty cache issue in interceptor * fix empty cache issue in interceptor --- .../DependencyInjection/Interceptor.php | 15 +++++++-------- src/CacheBundle/Tests/CacheWrapperTest.php | 2 -- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/CacheBundle/DependencyInjection/Interceptor.php b/src/CacheBundle/DependencyInjection/Interceptor.php index 026dd71..9c6d9bd 100644 --- a/src/CacheBundle/DependencyInjection/Interceptor.php +++ b/src/CacheBundle/DependencyInjection/Interceptor.php @@ -17,6 +17,10 @@ class Interceptor implements MethodInterceptorInterface, LoggerAwareInterface /** @var LoggerInterface */ protected $logger; + /** @var Reader */ + protected $reader; + /** @var AbstractCache */ + protected $cacheService; /** @var array */ private $cacheData; @@ -45,20 +49,15 @@ public function intercept(MethodInvocation $invocation) if ($cacheObj->isReset() || ($this->getCacheFlags($invocation->reflection) & Cache::STATE_RESET)) { - $data = null; + $data = false; } else { $data = $this->cacheService->get($cacheKey); } - if ($data) { + if ($data !== false) { $this->logger->debug('Cache hit for ' . $cacheKey); - return $data; - } - if ($cacheObj->isReset() || ($this->getCacheFlags($invocation->reflection) & Cache::STATE_RESET)) { - $this->logger->debug('Cache reset for ' . $cacheKey); - } else { - $this->logger->debug('Cache miss for ' . $cacheKey); + return $data; } $result = $invocation->proceed(); diff --git a/src/CacheBundle/Tests/CacheWrapperTest.php b/src/CacheBundle/Tests/CacheWrapperTest.php index c9efdf5..eb44556 100644 --- a/src/CacheBundle/Tests/CacheWrapperTest.php +++ b/src/CacheBundle/Tests/CacheWrapperTest.php @@ -47,8 +47,6 @@ public function testWithMultiParams() $object = $this->container->get('cache.testservice'); $result = $object->testWithMultipleParams(200, 300); - $logHandler = $this->getLogHandler(); - $this->assertEquals($result, $object->testWithMultipleParams(200, 300)); $this->assertEquals($result, $object->testWithMultipleParams(200, 150)); $this->assertEquals($result, $object->testWithMultipleParams(200, 150, 100));