mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-17 06:59:51 +00:00
Making FileEngine not greedily clear files in a directory that may belong to another cache configuration. Tests added. Fixes #754
This commit is contained in:
parent
cd255d5031
commit
8b6c974cd0
2 changed files with 32 additions and 0 deletions
4
cake/libs/cache/file.php
vendored
4
cake/libs/cache/file.php
vendored
|
@ -209,7 +209,11 @@ class FileEngine extends CacheEngine {
|
||||||
$now = time();
|
$now = time();
|
||||||
$threshold = $now - $this->settings['duration'];
|
$threshold = $now - $this->settings['duration'];
|
||||||
}
|
}
|
||||||
|
$prefixLength = strlen($this->settings['prefix']);
|
||||||
while (($entry = $dir->read()) !== false) {
|
while (($entry = $dir->read()) !== false) {
|
||||||
|
if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($this->_setKey($entry) === false) {
|
if ($this->_setKey($entry) === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
28
cake/tests/cases/libs/cache/file.test.php
vendored
28
cake/tests/cases/libs/cache/file.test.php
vendored
|
@ -273,6 +273,34 @@ class FileEngineTest extends CakeTestCase {
|
||||||
Cache::config('default', array('engine' => 'File', 'path' => CACHE));
|
Cache::config('default', array('engine' => 'File', 'path' => CACHE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that clear() doesn't wipe files not in the current engine's prefix.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testClearWithPrefixes() {
|
||||||
|
$FileOne =& new FileEngine();
|
||||||
|
$FileOne->init(array(
|
||||||
|
'prefix' => 'prefix_one_',
|
||||||
|
'duration' => DAY
|
||||||
|
));
|
||||||
|
$FileTwo =& new FileEngine();
|
||||||
|
$FileTwo->init(array(
|
||||||
|
'prefix' => 'prefix_two_',
|
||||||
|
'duration' => DAY
|
||||||
|
));
|
||||||
|
|
||||||
|
$data1 = $data2 = $expected = 'content to cache';
|
||||||
|
$FileOne->write('key_one', $data1, DAY);
|
||||||
|
$FileTwo->write('key_two', $data2, DAY);
|
||||||
|
|
||||||
|
$this->assertEqual($FileOne->read('key_one'), $expected);
|
||||||
|
$this->assertEqual($FileTwo->read('key_two'), $expected);
|
||||||
|
|
||||||
|
$FileOne->clear(false);
|
||||||
|
$this->assertEqual($FileTwo->read('key_two'), $expected, 'secondary config was cleared by accident.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testKeyPath method
|
* testKeyPath method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue