Cache constructor (this is a singleton).
public static singleton ( ) : |
||
Résultat | The cache singleton. |
public function teststartCallbackRAM() { $cache = CacheRAM::singleton(); if ($cache->isEnabled()) { $this->_startcallback($cache); } }
function someCachedStuff() { $cache = CacheRAM::singleton(); if (!$cache->start(new CacheKey("outside", 1))) { // not cached echo '<div>'; echo "some random bla bla" . rand(); echo '</div>'; $cache->end(); } }
<?php require_once __DIR__ . '/../src/Cache.php'; use Cachearium\Backend\CacheRAM; use Cachearium\CacheKey; $cache = CacheRAM::singleton(); // turn on page debugging on $cache::$debugOnPage = true; $cache->setLog(true); ?> <html> <head> <title>Cachearium debug probe</title> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <style> <?php $cache->cssDebug(); ?> body { margin-top: 80px; } .bigoutsidediv { width: 100%; } .mediumdiv { width: 96%; margin: 2%; border: 1px solid blue; height: 100px; }
public function testNothing() { CacheRAM::singleton(); }
public function testClearAll() { $cacheKey = new CacheKey('test', 1); $cacheData = new CacheData($cacheKey, 'test'); $caches = [CacheRAM::singleton(), CacheFilesystem::singleton()]; if (CacheMemcached::hasMemcachedExt()) { $caches[] = CacheMemcached::singleton(); } foreach ($caches as $cacheInst) { $cacheInst->enable()->storeData($cacheData); $retrievedData = $cacheInst->getData($cacheKey); $this->assertEquals($cacheData->getFirstData(), $retrievedData->getFirstData()); } CacheAbstract::clearAll(); foreach ($caches as $cacheInst) { try { $retrievedData = $cacheInst->getData($cacheKey); $this->fail('Cache should be empty after a clearAll call !'); } catch (\Cachearium\Exceptions\NotCachedException $e) { $this->assertTrue(true, 'All cache was cleaned'); } } }
/** * Clears all cache classes. * @codeCoverageIgnore */ public static function clearAll() { $caches = [\Cachearium\Backend\CacheRAM::singleton(), \Cachearium\Backend\CacheFilesystem::singleton(), \Cachearium\Backend\CacheMemcached::singleton()]; foreach ($caches as $cacheInst) { if ($cacheInst->isEnabled()) { $cacheInst->clear(); } } }
public function testClearRAM() { $cache = CacheRAM::singleton(); $this->setBigClean($cache); }
public function testStartNested() { $cache = CacheRAM::singleton(); if ($cache->isEnabled()) { $this->_startNested($cache); } }