mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
9d0502943a
commit
24abf517d6
2 changed files with 17 additions and 7 deletions
17
cake/libs/cache/file.php
vendored
17
cake/libs/cache/file.php
vendored
|
@ -32,6 +32,9 @@
|
||||||
if (!class_exists('folder')) {
|
if (!class_exists('folder')) {
|
||||||
uses ('folder');
|
uses ('folder');
|
||||||
}
|
}
|
||||||
|
if (!class_exists('file')) {
|
||||||
|
uses ('file');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* File Storage engine for cache
|
* File Storage engine for cache
|
||||||
*
|
*
|
||||||
|
@ -123,9 +126,9 @@ class FileEngine extends CacheEngine {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$serialized = serialize($data);
|
$data = serialize($data);
|
||||||
|
|
||||||
if (!$serialized) {
|
if (!$data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$expires = time() + $duration;
|
$expires = time() + $duration;
|
||||||
|
@ -135,7 +138,7 @@ class FileEngine extends CacheEngine {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_writeCache($fileName, $serialized, $expires);
|
return $this->_writeCache($fileName, $data, $expires);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get absolute filename for a key
|
* Get absolute filename for a key
|
||||||
|
@ -145,10 +148,10 @@ class FileEngine extends CacheEngine {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _getFilename($key) {
|
function _getFilename($key) {
|
||||||
$file = new File($this->_dir);
|
$file =& new File($this->_dir);
|
||||||
$key = implode(DS, array_map(array($file , 'safe'), explode(DS, $key)));
|
$path = array_map(array($file , 'safe'), explode(DS, $key));
|
||||||
$fileName = $this->_prefix . $key;
|
$key = array_pop($path);
|
||||||
$fullpath = $this->Folder->realpath($this->_dir . DS . $fileName);
|
$fullpath = $this->Folder->realpath($this->_dir . implode(DS, $path) . DS . $this->_prefix . $key);
|
||||||
if (!$this->Folder->inPath($fullpath, true)) {
|
if (!$this->Folder->inPath($fullpath, true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
7
cake/tests/cases/libs/cache/file.test.php
vendored
7
cake/tests/cases/libs/cache/file.test.php
vendored
|
@ -84,5 +84,12 @@ class FileEngineTest extends UnitTestCase {
|
||||||
$this->assertTrue($result);
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue