예제 #1
0
 function test_staleness()
 {
     global $ID;
     $ID = 'stale';
     $file = wikiFN($ID);
     # Prepare test page
     saveWikiText($ID, 'Fresh', 'Created');
     # Create stale cache
     $cache = new cache_renderer($ID, $file, 'xhtml');
     $cache->storeCache('Stale');
     $stale = $cache->retrieveCache();
     # Prepare stale cache for testing
     $time = filemtime($file);
     touch($cache->cache, $time);
     # Make the test
     $fresh = p_cached_output($file, 'xhtml', $ID);
     $this->assertNotEquals($fresh, $stale, 'Stale cache failed to expire');
 }
예제 #2
0
/**
 * Returns the given file parsed into the requested output format
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Chris Smith <*****@*****.**>
 */
function p_cached_output($file, $format = 'xhtml', $id = '')
{
    global $conf;
    $cache = new cache_renderer($id, $file, $format);
    if ($cache->useCache()) {
        $parsed = $cache->retrieveCache(false);
        if ($conf['allowdebug'] && $format == 'xhtml') {
            $parsed .= "\n<!-- cachefile {$cache->cache} used -->\n";
        }
    } else {
        $parsed = p_render($format, p_cached_instructions($file, false, $id), $info);
        if ($info['cache']) {
            $cache->storeCache($parsed);
            //save cachefile
            if ($conf['allowdebug'] && $format == 'xhtml') {
                $parsed .= "\n<!-- no cachefile used, but created {$cache->cache} -->\n";
            }
        } else {
            $cache->removeCache();
            //try to delete cachefile
            if ($conf['allowdebug'] && $format == 'xhtml') {
                $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n";
            }
        }
    }
    return $parsed;
}