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
This commit is contained in:
gwoo 2007-08-28 23:34:14 +00:00
parent 9d0502943a
commit 24abf517d6
2 changed files with 17 additions and 7 deletions

View file

@ -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;
}

View file

@ -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);
}
}
?>