From 06ec2d2aca7a44198986d2d93c996d6a6438f6fb Mon Sep 17 00:00:00 2001 From: Sotaro KARASAWA Date: Sun, 12 Jul 2009 03:56:43 +0900 Subject: [PATCH] Modified method behavior Ethna_Plugin_Cachemanager::getNamespace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - これまで意味をなしていなかった getNamespace を意味のあるものにした -- それにあわせてLocalfile, Memcache の実装の一部を変更 -- テストケースの更新 --- CHANGES | 1 + class/Plugin/Cachemanager.php | 9 +++++++-- class/Plugin/Cachemanager/Localfile.php | 10 +++++----- class/Plugin/Cachemanager/Memcache.php | 22 +++++++++++----------- .../Ethna_Plugin_Cachemanager_Localfile_Test.php | 19 ++++++++++++++----- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CHANGES b/CHANGES index 19cfffc..261af0f 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,7 @@ - ethna make-plugin-package のデフォルトインストールディレクトリが誤っていたバグを修正 - iniディレクティブ date.timezone が設定されてないために、E_WARNING が PHP 5.3.0 で出ていたバグを修正 - Ethna_Plugin::includePlugin メソッドの実装が動作するものではなかったので変更 +- Ethna_Plugin_Cachemanager のクラスのプロパティに指定する $namespace が意味をなしていなかったので修正 (#17753) ** 2.5.0-preview5 diff --git a/class/Plugin/Cachemanager.php b/class/Plugin/Cachemanager.php index fbe22ab..974500c 100644 --- a/class/Plugin/Cachemanager.php +++ b/class/Plugin/Cachemanager.php @@ -49,9 +49,14 @@ class Ethna_Plugin_Cachemanager extends Ethna_Plugin_Abstract * @access public * @return string 現在のキャッシュネームスペース */ - function getNamespace($namespace) + function getNamespace($namespace = null) { - return $this->namespace; + if ($namespace === null) { + return $this->namespace; + } + else { + return $namespace; + } } /** diff --git a/class/Plugin/Cachemanager/Localfile.php b/class/Plugin/Cachemanager/Localfile.php index 9379b28..1d889a7 100644 --- a/class/Plugin/Cachemanager/Localfile.php +++ b/class/Plugin/Cachemanager/Localfile.php @@ -38,7 +38,7 @@ class Ethna_Plugin_Cachemanager_Localfile extends Ethna_Plugin_Cachemanager */ function get($key, $lifetime = null, $namespace = null) { - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_file = $this->_getCacheFile($namespace, $key); // ライフタイムチェック @@ -103,7 +103,7 @@ class Ethna_Plugin_Cachemanager_Localfile extends Ethna_Plugin_Cachemanager */ function getLastModified($key, $namespace = null) { - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_file = $this->_getCacheFile($namespace, $key); clearstatcache(); @@ -124,7 +124,7 @@ class Ethna_Plugin_Cachemanager_Localfile extends Ethna_Plugin_Cachemanager */ function isCached($key, $lifetime = null, $namespace = null) { - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_file = $this->_getCacheFile($namespace, $key); // ライフタイムチェック @@ -153,7 +153,7 @@ class Ethna_Plugin_Cachemanager_Localfile extends Ethna_Plugin_Cachemanager */ function set($key, $value, $timestamp = null, $namespace = null) { - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $dir = $this->_getCacheDir($namespace, $key); // キャッシュディレクトリチェック @@ -207,7 +207,7 @@ class Ethna_Plugin_Cachemanager_Localfile extends Ethna_Plugin_Cachemanager */ function clear($key, $namespace = null) { - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_file = $this->_getCacheFile($namespace, $key); if (file_exists($cache_file)) { diff --git a/class/Plugin/Cachemanager/Memcache.php b/class/Plugin/Cachemanager/Memcache.php index 9543ab8..fe9aa57 100644 --- a/class/Plugin/Cachemanager/Memcache.php +++ b/class/Plugin/Cachemanager/Memcache.php @@ -41,13 +41,13 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager /**#@-*/ /** - * Memcacheクラスのコンストラクタ + * _load * - * @access public + * @access protected */ - function Ethna_Plugin_Cachemanager_Memcache(&$controller) + function _load() { - parent::Ethna_Plugin_Cachemanager($controller); + parent::_load(); $this->memcache_pool = array(); } @@ -101,7 +101,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager */ function _getMemcacheInfo($cache_key, $namespace) { - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $memcache_info = $this->config['info']; $default_memcache_host = $this->config['host']; @@ -149,7 +149,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager return Ethna::raiseError('memcache server not available', E_CACHE_NO_VALUE); } - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_key = $this->_getCacheKey($namespace, $key); if ($cache_key == null) { @@ -188,7 +188,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager return Ethna::raiseError('memcache server not available', E_CACHE_NO_VALUE); } - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_key = $this->_getCacheKey($namespace, $key); if ($cache_key == null) { @@ -231,7 +231,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager return Ethna::raiseError('memcache server not available', E_CACHE_NO_VALUE); } - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_key = $this->_getCacheKey($namespace, $key); if ($cache_key == null) { @@ -256,7 +256,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager return Ethna::raiseError('memcache server not available', E_CACHE_NO_VALUE); } - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_key = $this->_getCacheKey($namespace, $key); if ($cache_key == null) { @@ -283,7 +283,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager } // ロック用キャッシュデータを利用する - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_key = "lock::" . $this->_getCacheKey($namespace, $key); $lock_lifetime = 30; @@ -318,7 +318,7 @@ class Ethna_Plugin_Cachemanager_Memcache extends Ethna_Plugin_Cachemanager return Ethna::raiseError('memcache server not available', E_CACHE_LOCK_ERROR); } - $namespace = is_null($namespace) ? $this->namespace : $namespace; + $namespace = $this->getNamespace($namespace); $cache_key = "lock::" . $this->_getCacheKey($namespace, $key); $this->memcache->delete($cache_key, -1); diff --git a/test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Localfile_Test.php b/test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Localfile_Test.php index dbfb79e..380fd4d 100644 --- a/test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Localfile_Test.php +++ b/test/Plugin/Cachemanager/Ethna_Plugin_Cachemanager_Localfile_Test.php @@ -55,8 +55,17 @@ class Ethna_Plugin_Cachemanager_Localfile_Test extends Ethna_UnitTestBase function testCachemanagerLocalfileConfig() { - $this->assertTrue('miyazakiaoi', array_shift(array_slice(explode('/', $this->cm->_getCacheDir('test', 'int_key')), -4, 1))); - $this->assertTrue('default', array_shift(array_slice(explode('/', $this->cm->_getCacheDir('', 'string_key')), -4, 1))); + $this->assertEqual('miyazakiaoi', array_shift(array_slice(explode('/', $this->cm->_getCacheDir('test', 'int_key')), -4, 1))); + $this->assertEqual('default', array_shift(array_slice(explode('/', $this->cm->_getCacheDir('', 'string_key')), -4, 1))); + } + + function testCachemanagerLocalfileNamespace() + { + $namespace = "miyazakiaoi"; + $this->cm->setNamespace($namespace); + $this->assertEqual('miyazakiaoi', $this->cm->namespace); + $this->assertEqual('miyazakiaoi', $this->cm->getNamespace()); + $this->cm->setNamespace(""); } function testCachemanagerLocalfileInt() @@ -113,11 +122,11 @@ class Ethna_Plugin_Cachemanager_Localfile_Test extends Ethna_UnitTestBase // PHP 4, PHP5 ともに、Windows上ではmodeをどのように設定しても // read権限が残るためskip.(PHP 4.4.8, 5.2.6 on Windows XP) if (!ETHNA_OS_WINDOWS) { - Ethna_Util::chmod($this->cm->_getCacheFile(null, $string_key), 0222); + Ethna_Util::chmod($this->cm->_getCacheFile($this->cm->getNamespace(), $string_key), 0222); $pear_error = $this->cm->get($string_key); $this->assertEqual(E_CACHE_NO_VALUE, $pear_error->getCode()); $this->assertEqual('fopen failed', $pear_error->getMessage()); - Ethna_Util::chmod($this->cm->_getCacheFile(null, $string_key), 0666); + Ethna_Util::chmod($this->cm->_getCacheFile($this->cm->getNamespace(), $string_key), 0666); } // lifetime切れの場合 @@ -127,7 +136,7 @@ class Ethna_Plugin_Cachemanager_Localfile_Test extends Ethna_UnitTestBase // ディレクトリ名と同じファイルがあってディレクトリが作成できない場合 $tmp_key = 'tmpkey'; - $tmp_dirname = $this->cm->_getCacheDir(null, $tmp_key); + $tmp_dirname = $this->cm->_getCacheDir($this->cm->getNamespace(), $tmp_key); Ethna_Util::mkdir(dirname($tmp_dirname), 0777); $tmp_file = fopen($tmp_dirname, 'w'); fclose($tmp_file); -- 2.11.0