Skip to content

Commit

Permalink
Merge pull request #98 from doctrine/enhancement/#65-remove-cache-sal…
Browse files Browse the repository at this point in the history
…t-from-cached-reader

Enhancement/#65 remove cache salt from cached reader
  • Loading branch information
Ocramius authored Oct 24, 2016
2 parents fd51a7c + d0b24b6 commit dc44263
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
19 changes: 6 additions & 13 deletions lib/Doctrine/Common/Annotations/CachedReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
*/
final class CachedReader implements Reader
{
/**
* @var string
*/
private static $CACHE_SALT = '@[Annot]';

/**
* @var Reader
*/
Expand Down Expand Up @@ -183,14 +178,13 @@ public function clearLoadedAnnotations()
/**
* Fetches a value from the cache.
*
* @param string $rawCacheKey The cache key.
* @param ReflectionClass $class The related class.
* @param string $cacheKey The cache key.
* @param ReflectionClass $class The related class.
*
* @return mixed The cached value or false when the value is not in cache.
*/
private function fetchFromCache($rawCacheKey, ReflectionClass $class)
private function fetchFromCache($cacheKey, ReflectionClass $class)
{
$cacheKey = $rawCacheKey . self::$CACHE_SALT;
if (($data = $this->cache->fetch($cacheKey)) !== false) {
if (!$this->debug || $this->isCacheFresh($cacheKey, $class)) {
return $data;
Expand All @@ -203,14 +197,13 @@ private function fetchFromCache($rawCacheKey, ReflectionClass $class)
/**
* Saves a value to the cache.
*
* @param string $rawCacheKey The cache key.
* @param mixed $value The value.
* @param string $cacheKey The cache key.
* @param mixed $value The value.
*
* @return void
*/
private function saveToCache($rawCacheKey, $value)
private function saveToCache($cacheKey, $value)
{
$cacheKey = $rawCacheKey . self::$CACHE_SALT;
$this->cache->save($cacheKey, $value);
if ($this->debug) {
$this->cache->save('[C]'.$cacheKey, time());
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Common/Annotations/CachedReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testIgnoresStaleCacheWithInterfacesThatExtendOtherInterfaces()

protected function doTestCacheStale($className, $lastCacheModification)
{
$cacheKey = $className.'@[Annot]';
$cacheKey = $className;

$cache = $this->createMock('Doctrine\Common\Cache\Cache');
$cache
Expand Down Expand Up @@ -115,4 +115,4 @@ protected function getReader()
$this->cache = new ArrayCache();
return new CachedReader(new AnnotationReader(), $this->cache);
}
}
}

0 comments on commit dc44263

Please sign in to comment.