From 5439ab785467b7dbe7dd1f83e86533ceb8c35600 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 19 May 2014 11:29:34 -0400 Subject: [PATCH] Changed the default value of `Cache::keyPrefix` to be null. --- framework/CHANGELOG.md | 2 +- framework/UPGRADE.md | 4 ++++ framework/caching/Cache.php | 19 +++---------------- tests/unit/framework/caching/CacheTestCase.php | 10 ---------- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6c825a5..669a0b4 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -63,7 +63,7 @@ Yii Framework 2 Change Log - Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe) - Chg: `yii\data\ActiveDataProvider::$query` will not be modified directly with pagination and sorting anymore so it will be reuseable (cebe) - Chg: Removed `yii\rest\ActiveController::$transactional` property and connected functionality (samdark) - +- Chg: Changed the default value of the `keyPrefix` property of cache components to be null (qiangxue) 2.0.0-beta April 13, 2014 ------------------------- diff --git a/framework/UPGRADE.md b/framework/UPGRADE.md index ffbade4..71daf55 100644 --- a/framework/UPGRADE.md +++ b/framework/UPGRADE.md @@ -29,3 +29,7 @@ Upgrade from Yii 2.0 Beta `yii\filters\auth\HttpBearerAuth` authentication method, the value of this parameter will be `yii\filters\auth\HttpBearerAuth`. This allows you to differentiate access tokens taken by different authentication methods. + +* If you are sharing the same cache across different applications, you should configure + the `keyPrefix` property of the cache component to use some unique string. + Previously, this property was automatically assigned with a unique string. diff --git a/framework/caching/Cache.php b/framework/caching/Cache.php index 8be2b9d..73b90b8 100644 --- a/framework/caching/Cache.php +++ b/framework/caching/Cache.php @@ -7,7 +7,6 @@ namespace yii\caching; -use Yii; use yii\base\Component; use yii\helpers\StringHelper; @@ -52,10 +51,9 @@ use yii\helpers\StringHelper; abstract class Cache extends Component implements \ArrayAccess { /** - * @var string a string prefixed to every cache key so that it is unique. If not set, - * it will use a prefix generated from [[\yii\base\Application::id]]. You may set this property to be an empty string - * if you don't want to use key prefix. It is recommended that you explicitly set this property to some - * static value if the cached data needs to be shared among multiple applications. + * @var string a string prefixed to every cache key so that it is unique globally in the whole cache storage. + * It is recommended that you set a unique cache key prefix for each application if the same cache + * storage is being used by different applications. * * To ensure interoperability, only alphanumeric characters should be used. */ @@ -71,17 +69,6 @@ abstract class Cache extends Component implements \ArrayAccess */ public $serializer; - /** - * Initializes the application component. - * This method overrides the parent implementation by setting default cache key prefix. - */ - public function init() - { - parent::init(); - if ($this->keyPrefix === null) { - $this->keyPrefix = substr(md5(Yii::$app->id), 0, 5); - } - } /** * Builds a normalized cache key from a given key. diff --git a/tests/unit/framework/caching/CacheTestCase.php b/tests/unit/framework/caching/CacheTestCase.php index 0e595b9..40c7705 100644 --- a/tests/unit/framework/caching/CacheTestCase.php +++ b/tests/unit/framework/caching/CacheTestCase.php @@ -58,16 +58,6 @@ abstract class CacheTestCase extends TestCase return $cache; } - /** - * default value of cache prefix is application id - */ - public function testKeyPrefix() - { - $cache = $this->getCacheInstance(); - $this->assertNotNull(\Yii::$app->id); - $this->assertNotNull($cache->keyPrefix); - } - public function testSet() { $cache = $this->getCacheInstance();