Skip to content

Commit

Permalink
moved to psr 6
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbumbacea committed Dec 6, 2016
1 parent 3123858 commit cd4b894
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 950 deletions.
2 changes: 1 addition & 1 deletion app/config.yml
Expand Up @@ -13,7 +13,7 @@ monolog:

services:
cache.service:
class: CacheBundle\Service\MemoryCache
class: Symfony\Component\Cache\Adapter\ArrayAdapter
cache.testservice:
class: CacheBundle\Tests\CacheableClass
tags:
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Expand Up @@ -10,24 +10,23 @@
}
],
"require": {
"php": ">=5.5",
"php": ">=5.6",
"jms/aop-bundle": "1.*",
"psr/log": "~1",
"psr/cache": "1.0.*",
"doctrine/annotations": "@stable"
},
"suggest": {
"predis/predis": "1.0.*"
"symfony/cache": "3.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"phpunit/phpunit": "5.*",
"squizlabs/php_codesniffer": "2.*",
"phpmd/phpmd" : "@stable",
"phing/phing": "@stable",
"sebastian/phpcpd": "2.0.2",
"predis/predis": "1.0.*",
"symfony/cache": "3.*",
"satooshi/php-coveralls": "~1.0",
"ext-memcached": "*",
"ext-couchbase": "*",
"symfony/monolog-bundle": "@stable",
"symfony/framework-bundle": "@stable"
},
Expand Down
30 changes: 13 additions & 17 deletions src/CacheBundle/DependencyInjection/Interceptor.php
Expand Up @@ -5,10 +5,10 @@
use CacheBundle\CacheCompilerPass;
use CacheBundle\ContextAwareCache;
use CacheBundle\Exception\CacheException;
use CacheBundle\Service\AbstractCache;
use CG\Proxy\MethodInterceptorInterface;
use CG\Proxy\MethodInvocation;
use Doctrine\Common\Annotations\Reader;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

Expand All @@ -18,13 +18,13 @@ class Interceptor implements MethodInterceptorInterface, LoggerAwareInterface

/** @var Reader */
protected $reader;
/** @var AbstractCache */
/** @var CacheItemPoolInterface */
protected $cacheService;

/** @var array */
private $cacheData;

public function __construct(AbstractCache $cacheService, Reader $reader)
public function __construct(CacheItemPoolInterface $cacheService, Reader $reader)
{
$this->cacheService = $cacheService;
$this->reader = $reader;
Expand All @@ -41,27 +41,24 @@ public function __construct(AbstractCache $cacheService, Reader $reader)
public function intercept(MethodInvocation $invocation)
{
$refMethod = $invocation->reflection;
/** @var Cache $cacheObj */
$cacheObj = $this->reader->getMethodAnnotation($refMethod, CacheCompilerPass::CACHE_ANNOTATION_NAME);
/** @var Cache $annotation */
$annotation = $this->reader->getMethodAnnotation($refMethod, CacheCompilerPass::CACHE_ANNOTATION_NAME);

$cacheKey = $this->getCacheKey($invocation, $refMethod->getParameters(), $cacheObj);
$cacheKey = $this->getCacheKey($invocation, $refMethod->getParameters(), $annotation);

$cacheItem = $this->cacheService->getItem($cacheKey);

if ($cacheObj->isReset() || ($this->getCacheFlags($invocation->reflection) & Cache::STATE_RESET)) {
$data = false;
} else {
$data = $this->cacheService->get($cacheKey);
}

if ($data !== false) {
if ($cacheItem->isHit() && !$annotation->isReset() && !($this->getCacheFlags($invocation->reflection) & Cache::STATE_RESET)) {
$this->logger->debug('Cache hit for ' . $cacheKey);

return $data;
return $cacheItem->get();
}

$result = $invocation->proceed();

$this->cacheService->set($cacheKey, $result, $cacheObj->getTtl());
$cacheItem->set($result);
$cacheItem->expiresAfter($annotation->getTtl());
$this->cacheService->save($cacheItem);

return $result;
}
Expand All @@ -70,9 +67,8 @@ public function intercept(MethodInvocation $invocation)
* @param MethodInvocation $invocation
* @param \ReflectionParameter[] $refParams
* @param Cache $cacheObj
*
* @return string
* @internal param $refMethod
* @throws CacheException
*/
protected function getCacheKey(MethodInvocation $invocation, $refParams, Cache $cacheObj)
{
Expand Down
102 changes: 0 additions & 102 deletions src/CacheBundle/Service/AbstractCache.php

This file was deleted.

91 changes: 0 additions & 91 deletions src/CacheBundle/Service/ApcCache.php

This file was deleted.

0 comments on commit cd4b894

Please sign in to comment.