mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT: Added Object::clearCache() to clear a cache
BUGFIX: Make object cache testing more robust git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73059 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
08e2fc15ef
commit
67a1c6cda3
@ -676,6 +676,18 @@ abstract class Object {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cache for the given cacheToFile call
|
||||
*/
|
||||
public function clearCache($method, $ID = false, $arguments = array()) {
|
||||
$cacheName = $this->class . '_' . $method;
|
||||
if(!is_array($arguments)) $arguments = array($arguments);
|
||||
if($ID) $cacheName .= '_' . $ID;
|
||||
if(count($arguments)) $cacheName .= '_' . implode('_', $arguments);
|
||||
|
||||
unlink(TEMP_FOLDER . '/' . $this->sanitiseCachename($cacheName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
|
@ -198,6 +198,10 @@ class ObjectTest extends SapphireTest {
|
||||
public function testCacheToFile() {
|
||||
$obj = new ObjectTest_CacheTest();
|
||||
|
||||
$obj->clearCache('cacheMethod');
|
||||
$obj->clearCache('cacheMethod', null, array(true));
|
||||
$obj->clearCache('incNumber');
|
||||
|
||||
$this->assertEquals('noarg', $obj->cacheToFile('cacheMethod', -1));
|
||||
$this->assertEquals('hasarg', $obj->cacheToFile('cacheMethod', -1, null, array(true)));
|
||||
$this->assertEquals('hasarg', $obj->cacheToFile('cacheMethod', 3600, null, array(true)));
|
||||
@ -207,7 +211,7 @@ class ObjectTest extends SapphireTest {
|
||||
// -1 lifetime will ensure that the cache isn't read - number incremented
|
||||
$this->assertEquals(2, $obj->cacheToFile('incNumber', -1));
|
||||
// Number shouldn't be incremented now because we're using the cached version
|
||||
$this->assertEquals(2, $obj->cacheToFile('incNumber', 3600));
|
||||
$this->assertEquals(2, $obj->cacheToFile('incNumber'));
|
||||
}
|
||||
|
||||
public function testExtend() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user