mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding prefix based cache clearning to Wincache.
This matches APC and Memcache. Fixes #1911
This commit is contained in:
parent
ef921fa56f
commit
0091fac5b9
3 changed files with 21 additions and 5 deletions
|
@ -110,7 +110,7 @@ class ApcEngine extends CacheEngine {
|
|||
*
|
||||
* @param boolean $check If true, nothing will be cleared, as entries are removed
|
||||
* from APC as they expired. This flag is really only used by FileEngine.
|
||||
* @return boolean True if the cache was successfully cleared, false otherwise
|
||||
* @return boolean True Returns true.
|
||||
*/
|
||||
public function clear($check) {
|
||||
if ($check) {
|
||||
|
|
|
@ -112,13 +112,27 @@ class WincacheEngine extends CacheEngine {
|
|||
}
|
||||
|
||||
/**
|
||||
* Delete all keys from the cache. This will clear every cache value stored
|
||||
* in wincache.
|
||||
* Delete all keys from the cache. This will clear every
|
||||
* item in the cache matching the cache config prefix.
|
||||
*
|
||||
* @return boolean True if the cache was successfully cleared, false otherwise
|
||||
*
|
||||
* @param boolean $check If true, nothing will be cleared, as entries will
|
||||
* naturally expire in wincache..
|
||||
* @return boolean True Returns true.
|
||||
*/
|
||||
public function clear($check) {
|
||||
return wincache_ucache_clear();
|
||||
if ($check) {
|
||||
return true;
|
||||
}
|
||||
$info = wincache_ucache_info();
|
||||
$cacheKeys = $info['ucache_entries'];
|
||||
unset($info);
|
||||
foreach ($cacheKeys as $key) {
|
||||
if (strpos($key['key_name'], $this->settings['prefix']) === 0) {
|
||||
wincache_ucache_delete($key['key_name']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -188,10 +188,12 @@ class WincacheEngineTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testClear() {
|
||||
wincache_ucache_set('not_cake', 'safe');
|
||||
Cache::write('some_value', 'value', 'wincache');
|
||||
|
||||
$result = Cache::clear(false, 'wincache');
|
||||
$this->assertTrue($result);
|
||||
$this->assertFalse(Cache::read('some_value', 'wincache'));
|
||||
$this->assertEquals('safe', wincache_ucache_get('not_cake'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue