From 24abf517d679d7a340ef6e2216c1625c94ba0eba Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 28 Aug 2007 23:34:14 +0000 Subject: [PATCH] updating file cache engine, fixes #3041 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5595 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/cache/file.php | 17 ++++++++++------- cake/tests/cases/libs/cache/file.test.php | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index f3a5fb588..95d087644 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -32,6 +32,9 @@ if (!class_exists('folder')) { uses ('folder'); } +if (!class_exists('file')) { + uses ('file'); +} /** * File Storage engine for cache * @@ -123,9 +126,9 @@ class FileEngine extends CacheEngine { return false; } - $serialized = serialize($data); + $data = serialize($data); - if (!$serialized) { + if (!$data) { return false; } $expires = time() + $duration; @@ -135,7 +138,7 @@ class FileEngine extends CacheEngine { return false; } - return $this->_writeCache($fileName, $serialized, $expires); + return $this->_writeCache($fileName, $data, $expires); } /** * Get absolute filename for a key @@ -145,10 +148,10 @@ class FileEngine extends CacheEngine { * @access private */ function _getFilename($key) { - $file = new File($this->_dir); - $key = implode(DS, array_map(array($file , 'safe'), explode(DS, $key))); - $fileName = $this->_prefix . $key; - $fullpath = $this->Folder->realpath($this->_dir . DS . $fileName); + $file =& new File($this->_dir); + $path = array_map(array($file , 'safe'), explode(DS, $key)); + $key = array_pop($path); + $fullpath = $this->Folder->realpath($this->_dir . implode(DS, $path) . DS . $this->_prefix . $key); if (!$this->Folder->inPath($fullpath, true)) { return false; } diff --git a/cake/tests/cases/libs/cache/file.test.php b/cake/tests/cases/libs/cache/file.test.php index 12ea74bb3..261a1d4c9 100644 --- a/cake/tests/cases/libs/cache/file.test.php +++ b/cake/tests/cases/libs/cache/file.test.php @@ -84,5 +84,12 @@ class FileEngineTest extends UnitTestCase { $this->assertTrue($result); } + function testCacheName() { + $cache =& Cache::getInstance(); + $result = $cache->_Engine->_getFilename('models' . DS . 'default_' . 'posts'); + $expecting = CACHE . 'models' . DS .'cake_default_posts'; + $this->assertEqual($result, $expecting); + } + } ?> \ No newline at end of file