fetch() public method

Fetch the cached content
public fetch ( string $id ) : string
$id string cache id (e.g. a filename)
return string
function test_Minify_Cache_File()
{
    $data = str_repeat(md5(time()) . 'í', 100);
    // 3400 bytes in UTF-8
    $id = 'Minify_test_cache_noLock';
    $prefix = 'Minify_Cache_File : ';
    $cache = new Minify_Cache_File();
    echo "NOTE: Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
    assertTrue(true === $cache->store($id, $data), $prefix . 'store');
    assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
    assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
    ob_start();
    $cache->display($id);
    $displayed = ob_get_contents();
    ob_end_clean();
    assertTrue($data === $displayed, $prefix . 'display');
    assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
    // test with locks
    $id = 'Minify_test_cache_withLock';
    $cache = new Minify_Cache_File('', true);
    assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
    assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
    assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
    ob_start();
    $cache->display($id);
    $displayed = ob_get_contents();
    ob_end_clean();
    assertTrue($data === $displayed, $prefix . 'display w/ lock');
    assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock');
}
function test_Minify_Cache_File()
{
    global $minifyCachePath;
    $data = str_repeat(md5(time()), 160);
    $id = 'Minify_test_cache_noLock';
    $prefix = 'Minify_Cache_File : ';
    $cache = new Minify_Cache_File($minifyCachePath);
    assertTrue(true === $cache->store($id, $data), $prefix . 'store');
    assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
    assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
    ob_start();
    $cache->display($id);
    $displayed = ob_get_contents();
    ob_end_clean();
    assertTrue($data === $displayed, $prefix . 'display');
    assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
    // test with locks
    $id = 'Minify_test_cache_withLock';
    $cache = new Minify_Cache_File($minifyCachePath, true);
    assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
    assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
    assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
    ob_start();
    $cache->display($id);
    $displayed = ob_get_contents();
    ob_end_clean();
    assertTrue($data === $displayed, $prefix . 'display w/ lock');
    assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock');
}
示例#3
0
 static function getCache($file)
 {
     $cache = new Minify_Cache_File();
     $dir = dirname($file);
     $cache_path = $cache->getPath() . "/{$dir}";
     // FIX: create the dir if not available
     if (!is_dir($cache_path)) {
         mkdir($cache_path, 0775, true);
     }
     // check if the file is less than an hour old
     return $cache->isValid($file, time("now") - 3600) ? $cache->fetch($file) : false;
 }
示例#4
0
 function getCache($path)
 {
     $cache = new Minify_Cache_File();
     // check if the file is less than an hour old
     //return ( $cache->isValid($path, time("now")-3600) ) ? $cache->fetch($path) : false;
     return $cache->fetch($path);
 }