mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
updating cache engines so key will expire when duration is changed, updated datasource and configure to for new settings, closes #5083
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7364 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
4451c02b1c
commit
caa7bb6218
11 changed files with 80 additions and 45 deletions
|
@ -378,6 +378,9 @@ class CacheEngine extends Object {
|
|||
*/
|
||||
function init($settings = array()) {
|
||||
$this->settings = array_merge(array('prefix' => 'cake_', 'duration'=> 3600, 'probability'=> 100), $this->settings, $settings);
|
||||
if (!is_numeric($this->settings['duration'])) {
|
||||
$this->settings['duration'] = strtotime($this->settings['duration']) - time();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
|
|
7
cake/libs/cache/apc.php
vendored
7
cake/libs/cache/apc.php
vendored
|
@ -57,6 +57,8 @@ class ApcEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function write($key, &$value, $duration) {
|
||||
$expires = time() + $duration;
|
||||
apc_store($key.'_expires', $expires, $duration);
|
||||
return apc_store($key, $value, $duration);
|
||||
}
|
||||
/**
|
||||
|
@ -67,6 +69,11 @@ class ApcEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function read($key) {
|
||||
$time = time();
|
||||
$cachetime = intval(apc_fetch($key.'_expires'));
|
||||
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
|
||||
return false;
|
||||
}
|
||||
return apc_fetch($key);
|
||||
}
|
||||
/**
|
||||
|
|
8
cake/libs/cache/file.php
vendored
8
cake/libs/cache/file.php
vendored
|
@ -128,9 +128,6 @@ class FileEngine extends CacheEngine {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($duration == null) {
|
||||
$duration = $this->settings['duration'];
|
||||
}
|
||||
$lineBreak = "\n";
|
||||
|
||||
if ($this->settings['isWindows']) {
|
||||
|
@ -168,9 +165,10 @@ class FileEngine extends CacheEngine {
|
|||
if ($this->settings['lock']) {
|
||||
$this->__File->lock = true;
|
||||
}
|
||||
$cachetime = $this->__File->read(11);
|
||||
$time = time();
|
||||
$cachetime = intval($this->__File->read(11));
|
||||
|
||||
if ($cachetime !== false && intval($cachetime) < time()) {
|
||||
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
|
||||
$this->__File->close();
|
||||
$this->__File->delete();
|
||||
return false;
|
||||
|
|
7
cake/libs/cache/memcache.php
vendored
7
cake/libs/cache/memcache.php
vendored
|
@ -100,6 +100,8 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function write($key, &$value, $duration) {
|
||||
$expires = time() + $duration;
|
||||
$this->__Memcache->set($key.'_expires', $expires, $this->settings['compress'], $duration);
|
||||
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
|
||||
}
|
||||
/**
|
||||
|
@ -110,6 +112,11 @@ class MemcacheEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function read($key) {
|
||||
$time = time();
|
||||
$cachetime = intval($this->__Memcache->get($key.'_expires'));
|
||||
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
|
||||
return false;
|
||||
}
|
||||
return $this->__Memcache->get($key);
|
||||
}
|
||||
/**
|
||||
|
|
7
cake/libs/cache/xcache.php
vendored
7
cake/libs/cache/xcache.php
vendored
|
@ -69,6 +69,8 @@ class XcacheEngine extends CacheEngine {
|
|||
* @access public
|
||||
*/
|
||||
function write($key, &$value, $duration) {
|
||||
$expires = time() + $duration;
|
||||
xcache_set($key.'_expires', $expires, $duration);
|
||||
return xcache_set($key, $value, $duration);
|
||||
}
|
||||
/**
|
||||
|
@ -80,6 +82,11 @@ class XcacheEngine extends CacheEngine {
|
|||
*/
|
||||
function read($key) {
|
||||
if (xcache_isset($key)) {
|
||||
$time = time();
|
||||
$cachetime = intval(xcache_get($key.'_expires'));
|
||||
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
|
||||
return false;
|
||||
}
|
||||
return xcache_get($key);
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -659,7 +659,9 @@ class Configure extends Object {
|
|||
|
||||
$duration = $cache['settings']['duration'];
|
||||
if (Configure::read() >= 1) {
|
||||
$duration = 10;
|
||||
$duration = '+10 seconds';
|
||||
} else {
|
||||
$duration = '+999 days';
|
||||
}
|
||||
|
||||
if (Cache::config('_cake_core_') === false) {
|
||||
|
|
|
@ -199,18 +199,12 @@ class DataSource extends Object {
|
|||
return $this->_sources;
|
||||
}
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
$expires = "+30 seconds";
|
||||
} else {
|
||||
$expires = "+999 days";
|
||||
}
|
||||
|
||||
$key = ConnectionManager::getSourceName($this) . '_' . Inflector::slug($this->config['database']) . '_list';
|
||||
$sources = Cache::read($key, '_cake_model_');
|
||||
|
||||
if ($sources == null) {
|
||||
if (empty($sources)) {
|
||||
$sources = $data;
|
||||
Cache::write($key, $data, array('duration' => $expires, 'config' => '_cake_model_'));
|
||||
Cache::write($key, $data, '_cake_model_');
|
||||
}
|
||||
|
||||
$this->_sources = $sources;
|
||||
|
@ -385,11 +379,6 @@ class DataSource extends Object {
|
|||
if ($this->cacheSources === false) {
|
||||
return null;
|
||||
}
|
||||
if (Configure::read() > 0) {
|
||||
$expires = "+15 seconds";
|
||||
} else {
|
||||
$expires = "+999 days";
|
||||
}
|
||||
|
||||
if ($data !== null) {
|
||||
$this->__descriptions[$object] =& $data;
|
||||
|
@ -400,7 +389,7 @@ class DataSource extends Object {
|
|||
|
||||
if (empty($cache)) {
|
||||
$cache = $data;
|
||||
Cache::write($key, $cache, array('duration' => $expires, 'config' => '_cake_model_'));
|
||||
Cache::write($key, $cache, '_cake_model_');
|
||||
}
|
||||
|
||||
return $cache;
|
||||
|
|
|
@ -99,6 +99,7 @@ class CacheTest extends CakeTestCase {
|
|||
'duration' => 3600,
|
||||
'probability' => 100,
|
||||
'engine' => 'File',
|
||||
'isWindows' => (substr(PHP_OS, 0, 3) == "WIN")
|
||||
);
|
||||
$this->assertEqual($expected, Cache::settings('File'));
|
||||
}
|
||||
|
@ -118,13 +119,14 @@ class CacheTest extends CakeTestCase {
|
|||
'path'=> TMP . 'tests',
|
||||
'prefix'=> 'cake_',
|
||||
'lock' => false,
|
||||
'serialize'=> true
|
||||
'serialize'=> true,
|
||||
'isWindows' => (substr(PHP_OS, 0, 3) == "WIN")
|
||||
);
|
||||
$this->assertEqual($settings, $expecting);
|
||||
}
|
||||
/**
|
||||
* testWriteEmptyValues method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
|
7
cake/tests/cases/libs/cache/file.test.php
vendored
7
cake/tests/cases/libs/cache/file.test.php
vendored
|
@ -294,9 +294,7 @@ class FileEngineTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testRemoveWindowsSlashesFromCache() {
|
||||
Cache::engine('File', array('isWindows' => true, 'prefix' => null, 'path' => TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'tmp'));
|
||||
|
||||
$data = Cache::read('dir_map');
|
||||
Cache::engine('File', array('isWindows' => true, 'prefix' => null, 'path' => TMP));
|
||||
|
||||
$expected = array (
|
||||
'C:\dev\prj2\sites\cake\libs' => array(
|
||||
|
@ -326,6 +324,9 @@ class FileEngineTest extends CakeTestCase {
|
|||
'C:\dev\prj2\sites\main_site\views\helpers' => array(
|
||||
0 => 'C:\dev\prj2\sites\main_site\views\helpers'));
|
||||
|
||||
$data = Cache::write('test_dir_map', $expected);
|
||||
$data = Cache::read('test_dir_map');
|
||||
Cache::delete('dir_map');
|
||||
$this->assertEqual($expected, $data);
|
||||
}
|
||||
|
||||
|
|
33
cake/tests/cases/libs/cache/memcache.test.php
vendored
33
cake/tests/cases/libs/cache/memcache.test.php
vendored
|
@ -36,14 +36,14 @@ if (!class_exists('Cache')) {
|
|||
*/
|
||||
/**
|
||||
* MemcacheEngineTest class
|
||||
*
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.cache
|
||||
*/
|
||||
class MemcacheEngineTest extends UnitTestCase {
|
||||
/**
|
||||
* skip method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -56,7 +56,7 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -65,7 +65,7 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -82,7 +82,7 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testConnect method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -94,7 +94,7 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -113,7 +113,7 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -137,10 +137,25 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
sleep(2);
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = 'this is a test of the emergency broadcasting system';
|
||||
$result = Cache::write('other_test', $data);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertEqual($result, $data);
|
||||
|
||||
Cache::engine('Memcache', array('duration' => '+1 second'));
|
||||
sleep(2);
|
||||
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::engine('Memcache', array('duration' => 3600));
|
||||
}
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -154,7 +169,7 @@ class MemcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
|
26
cake/tests/cases/libs/cache/xcache.test.php
vendored
26
cake/tests/cases/libs/cache/xcache.test.php
vendored
|
@ -38,7 +38,7 @@ if (!class_exists('Cache')) {
|
|||
class XcacheEngineTest extends UnitTestCase {
|
||||
/**
|
||||
* skip method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -51,7 +51,7 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -60,7 +60,7 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testSettings method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -70,14 +70,14 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
'duration'=> 3600,
|
||||
'probability' => 100,
|
||||
'engine' => 'Xcache',
|
||||
'PHP_AUTH_USER' => 'cake',
|
||||
'PHP_AUTH_PW' => 'cake',
|
||||
'PHP_AUTH_USER' => 'user',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
);
|
||||
$this->assertEqual($settings, $expecting);
|
||||
}
|
||||
/**
|
||||
* testReadAndWriteCache method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -96,11 +96,13 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* testExpiry method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testExpiry() {
|
||||
Cache::engine('Xcache', array('duration' => 4));
|
||||
|
||||
sleep(3);
|
||||
$result = Cache::read('test');
|
||||
$this->assertFalse($result);
|
||||
|
@ -109,7 +111,7 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
$result = Cache::write('other_test', $data, 1);
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(3);
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
|
@ -117,13 +119,15 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
$result = Cache::write('other_test', $data, "+1 second");
|
||||
$this->assertTrue($result);
|
||||
|
||||
sleep(3);
|
||||
sleep(2);
|
||||
$result = Cache::read('other_test');
|
||||
$this->assertFalse($result);
|
||||
|
||||
Cache::engine('Xcache', array('duration' => 3600));
|
||||
}
|
||||
/**
|
||||
* testDeleteCache method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
@ -137,7 +141,7 @@ class XcacheEngineTest extends UnitTestCase {
|
|||
}
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue