1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Introduced getCacheEntryKey() to combine region name and cache key

This commit is contained in:
Menno Holtkamp 2015-04-14 09:52:25 +02:00
parent dbc29d28d2
commit 34b6ce9259
2 changed files with 19 additions and 6 deletions

View File

@ -57,8 +57,9 @@ class DefaultMultiGetRegion extends DefaultRegion
public function getMultiple(CollectionCacheEntry $collection) public function getMultiple(CollectionCacheEntry $collection)
{ {
$keysToRetrieve = array(); $keysToRetrieve = array();
foreach ($collection->identifiers as $index => $key) { foreach ($collection->identifiers as $index => $key) {
$keysToRetrieve[$index] = $this->name . '_' . $key->hash; $keysToRetrieve[$index] = $this->getCacheEntryKey($key);
} }
$items = $this->cache->fetchMultiple($keysToRetrieve); $items = $this->cache->fetchMultiple($keysToRetrieve);
@ -70,6 +71,7 @@ class DefaultMultiGetRegion extends DefaultRegion
foreach ($keysToRetrieve as $index => $key) { foreach ($keysToRetrieve as $index => $key) {
$returnableItems[$index] = $items[$key]; $returnableItems[$index] = $items[$key];
} }
return $returnableItems; return $returnableItems;
} }
} }

View File

@ -36,6 +36,8 @@ use Doctrine\ORM\Cache\Region;
*/ */
class DefaultRegion implements Region class DefaultRegion implements Region
{ {
const REGION_KEY_SEPARATOR = '_';
/** /**
* @var CacheAdapter * @var CacheAdapter
*/ */
@ -84,7 +86,7 @@ class DefaultRegion implements Region
*/ */
public function contains(CacheKey $key) public function contains(CacheKey $key)
{ {
return $this->cache->contains($this->name . '_' . $key->hash); return $this->cache->contains($this->getCacheEntryKey($key));
} }
/** /**
@ -92,7 +94,7 @@ class DefaultRegion implements Region
*/ */
public function get(CacheKey $key) public function get(CacheKey $key)
{ {
return $this->cache->fetch($this->name . '_' . $key->hash) ?: null; return $this->cache->fetch($this->getCacheEntryKey($key)) ?: null;
} }
/** /**
@ -103,7 +105,7 @@ class DefaultRegion implements Region
$result = array(); $result = array();
foreach ($collection->identifiers as $key) { foreach ($collection->identifiers as $key) {
$entry = $this->cache->fetch($this->name . '_' . $key->hash); $entry = $this->cache->fetch($this->getCacheEntryKey($key));
if ($entry === false) { if ($entry === false) {
$result = null; $result = null;
break; break;
@ -115,12 +117,21 @@ class DefaultRegion implements Region
return $result; return $result;
} }
/**
* @param CacheKey $key
* @return string
*/
protected function getCacheEntryKey(CacheKey $key)
{
return $this->name . self::REGION_KEY_SEPARATOR . $key->hash;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null) public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null)
{ {
return $this->cache->save($this->name . '_' . $key->hash, $entry, $this->lifetime); return $this->cache->save($this->getCacheEntryKey($key), $entry, $this->lifetime);
} }
/** /**
@ -128,7 +139,7 @@ class DefaultRegion implements Region
*/ */
public function evict(CacheKey $key) public function evict(CacheKey $key)
{ {
return $this->cache->delete($this->name . '_' . $key->hash); return $this->cache->delete($this->getCacheEntryKey($key));
} }
/** /**