2010-01-21 23:09:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CacheTest extends SapphireTest {
|
|
|
|
|
|
|
|
function testCacheBasics() {
|
2010-02-02 05:06:51 +01:00
|
|
|
$cache = SS_Cache::factory('test');
|
2010-01-21 23:09:51 +01:00
|
|
|
|
|
|
|
$cache->save('Good', 'cachekey');
|
|
|
|
$this->assertEquals('Good', $cache->load('cachekey'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCacheCanBeDisabled() {
|
2010-02-02 05:06:51 +01:00
|
|
|
SS_Cache::set_cache_lifetime('test', -1, 10);
|
2010-01-21 23:09:51 +01:00
|
|
|
|
2010-02-02 05:06:51 +01:00
|
|
|
$cache = SS_Cache::factory('test');
|
2010-01-21 23:09:51 +01:00
|
|
|
|
|
|
|
$cache->save('Good', 'cachekey');
|
|
|
|
$this->assertFalse($cache->load('cachekey'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCacheLifetime() {
|
2010-02-08 21:08:50 +01:00
|
|
|
SS_Cache::set_cache_lifetime('test', 0.5, 20);
|
2010-01-21 23:09:51 +01:00
|
|
|
|
2010-02-02 05:06:51 +01:00
|
|
|
$cache = SS_Cache::factory('test');
|
2010-01-21 23:09:51 +01:00
|
|
|
|
|
|
|
$cache->save('Good', 'cachekey');
|
|
|
|
$this->assertEquals('Good', $cache->load('cachekey'));
|
|
|
|
|
2010-02-08 21:08:50 +01:00
|
|
|
sleep(1);
|
2010-01-21 23:09:51 +01:00
|
|
|
|
|
|
|
$this->assertFalse($cache->load('cachekey'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCacheSeperation() {
|
2010-02-02 05:06:51 +01:00
|
|
|
$cache1 = SS_Cache::factory('test1');
|
|
|
|
$cache2 = SS_Cache::factory('test2');
|
2010-01-21 23:09:51 +01:00
|
|
|
|
|
|
|
$cache1->save('Foo', 'cachekey');
|
|
|
|
$cache2->save('Bar', 'cachekey');
|
|
|
|
$this->assertEquals('Foo', $cache1->load('cachekey'));
|
|
|
|
$this->assertEquals('Bar', $cache2->load('cachekey'));
|
|
|
|
|
|
|
|
$cache1->remove('cachekey');
|
|
|
|
$this->assertFalse($cache1->load('cachekey'));
|
|
|
|
$this->assertEquals('Bar', $cache2->load('cachekey'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|