mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
update Cache to specify key paths with dot syntax, like Cache::write('my.key.is.here', $data);
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5866 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
aaca183da1
commit
a9a9a824e2
2 changed files with 35 additions and 6 deletions
|
@ -191,10 +191,10 @@ class Cache extends Object {
|
|||
return false;
|
||||
}
|
||||
|
||||
$key = strval($key);
|
||||
if (empty($key)) {
|
||||
if (!$key = $_this->__key($key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_resource($value)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -228,8 +228,7 @@ class Cache extends Object {
|
|||
if (!$_this->isInitialized($engine)) {
|
||||
return false;
|
||||
}
|
||||
$key = strval($key);
|
||||
if (empty($key)) {
|
||||
if (!$key = $_this->__key($key)) {
|
||||
return false;
|
||||
}
|
||||
$success = $_this->_Engine[$engine]->read($key);
|
||||
|
@ -253,10 +252,11 @@ class Cache extends Object {
|
|||
if (!$_this->isInitialized($engine)) {
|
||||
return false;
|
||||
}
|
||||
$key = strval($key);
|
||||
if (empty($key)) {
|
||||
|
||||
if (!$key = $_this->__key($key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = $_this->_Engine[$engine]->delete($key);
|
||||
$_this->_Engine[$engine]->init($settings);
|
||||
return $success;
|
||||
|
@ -317,6 +317,20 @@ class Cache extends Object {
|
|||
}
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* generates a safe key
|
||||
*
|
||||
* @param string $key the key passed over
|
||||
* @return mixed string $key or false
|
||||
* @access private
|
||||
*/
|
||||
function __key($key) {
|
||||
if (empty($key)) {
|
||||
return false;
|
||||
}
|
||||
$key = r(array(DS, '/', '.'), '_', strval($key));
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Storage engine for CakePHP caching
|
||||
|
|
15
cake/tests/cases/libs/cache/file.test.php
vendored
15
cake/tests/cases/libs/cache/file.test.php
vendored
|
@ -50,6 +50,9 @@ class FileEngineTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testReadAndWriteCache() {
|
||||
$result = Cache::write(null, 'here');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = Cache::read('test');
|
||||
$expecting = '';
|
||||
$this->assertEqual($result, $expecting);
|
||||
|
@ -151,6 +154,18 @@ class FileEngineTest extends UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
function testKeyPath() {
|
||||
$result = Cache::write('views.countries.something', 'here');
|
||||
$this->assertTrue($result);
|
||||
$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something'));
|
||||
|
||||
$result = Cache::read('views.countries.something');
|
||||
$this->assertEqual($result, 'here');
|
||||
|
||||
$result = Cache::clear();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
Cache::config('default');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue