public static function init()
 {
     $cache = new \Gregwar\Cache\Cache();
     $cache->setCacheDirectory(CACHE_DIR);
     return $cache;
 }
示例#2
0
<?php

include '../autoload.php';
$cache = new Gregwar\Cache\Cache();
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function () {
    echo "First call: generating file...\n";
    return strtoupper(file_get_contents('original.txt'));
});
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function () {
    echo "Second call: generating file, this should not happen!...\n";
    return strtoupper(file_get_contents('original.txt'));
});
echo "Waiting 4s...\n";
sleep(4);
$data = $cache->getOrCreate('uppercase.txt', array('max-age' => 2), function () {
    echo "Third call: generating cache file, because it expired...\n";
    return strtoupper(file_get_contents('original.txt'));
});
示例#3
0
 /**
  * Testing caching a form
  */
 public function testCache()
 {
     $cache = new Gregwar\Cache\Cache();
     $cache->setCacheDirectory($this->getCacheDirectory());
     $form = $this->getForm('basic.html', null, $cache);
     $html = "{$form}";
     $this->assertContains('toto', $html);
     $this->assertEquals(false, $form->isCached);
     $form = $this->getForm('basic.html', null, $cache);
     $html = "{$form}";
     $this->assertContains('toto', $html);
     $this->assertEquals(true, $form->isCached);
 }