From 0ab5bbaf40dad32ea26a9481fb5ea53e8adf58d8 Mon Sep 17 00:00:00 2001 From: votintsev Date: Sun, 26 May 2013 23:32:42 +0400 Subject: [PATCH] Update Cache.php Moved add prefix ($this->keyPrefix) to the key in function buildKey(). Could it be better? --- framework/yii/caching/Cache.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/framework/yii/caching/Cache.php b/framework/yii/caching/Cache.php index 0329078..0460b8c 100644 --- a/framework/yii/caching/Cache.php +++ b/framework/yii/caching/Cache.php @@ -98,15 +98,16 @@ abstract class Cache extends Component implements \ArrayAccess * ~~~ * * @param array|string $key the key to be normalized - * @return string the generated cache key + * @return string the generated cache key include $this->keyPrefix */ public function buildKey($key) { if (is_string($key)) { - return ctype_alnum($key) && StringHelper::strlen($key) <= 32 ? $key : md5($key); + $key = ctype_alnum($key) && StringHelper::strlen($key) <= 32 ? $key : md5($key); } else { - return md5(json_encode($key)); + $key = md5(json_encode($key)); } + return $this->keyPrefix . $key; } /** @@ -117,7 +118,7 @@ abstract class Cache extends Component implements \ArrayAccess */ public function get($key) { - $key = $this->keyPrefix . $this->buildKey($key); + $key = $this->buildKey($key); $value = $this->getValue($key); if ($value === false || $this->serializer === false) { return $value; @@ -147,7 +148,7 @@ abstract class Cache extends Component implements \ArrayAccess { $keyMap = array(); foreach ($keys as $key) { - $keyMap[$key] = $this->keyPrefix . $this->buildKey($key); + $keyMap[$key] = $this->buildKey($key); } $values = $this->getValues(array_values($keyMap)); $results = array(); @@ -192,7 +193,7 @@ abstract class Cache extends Component implements \ArrayAccess } elseif ($this->serializer !== false) { $value = call_user_func($this->serializer[0], array($value, $dependency)); } - $key = $this->keyPrefix . $this->buildKey($key); + $key = $this->buildKey($key); return $this->setValue($key, $value, $expire); } @@ -217,7 +218,7 @@ abstract class Cache extends Component implements \ArrayAccess } elseif ($this->serializer !== false) { $value = call_user_func($this->serializer[0], array($value, $dependency)); } - $key = $this->keyPrefix . $this->buildKey($key); + $key = $this->buildKey($key); return $this->addValue($key, $value, $expire); } @@ -228,7 +229,7 @@ abstract class Cache extends Component implements \ArrayAccess */ public function delete($key) { - $key = $this->keyPrefix . $this->buildKey($key); + $key = $this->buildKey($key); return $this->deleteValue($key); }