/** * @group flaky */ function test_confnocaching() { global $conf; $conf['cachetime'] = -1; // disables renderer caching $this->assertFalse($this->cache->useCache()); $this->assertNotEmpty($this->cache->_nocache); }
/** * @group slow */ function test_cache_handling() { $testid = 'wiki:bar:test'; saveWikiText($testid, '[[wiki:foo:]]', 'Test setup'); idx_addPage($testid); saveWikiText('wiki:foo:start', 'bar', 'Test setup'); idx_addPage('wiki:foo:start'); sleep(1); // wait in order to make sure that conditions with < give the right result. p_wiki_xhtml($testid); // populate cache $cache = new cache_renderer($testid, wikiFN($testid), 'xhtml'); $this->assertTrue($cache->useCache()); /** @var helper_plugin_move_op $move */ $move = plugin_load('helper', 'move_op'); $this->assertTrue($move->movePage('wiki:foo:start', 'wiki:foo2:start')); $cache = new cache_renderer($testid, wikiFN($testid), 'xhtml'); $this->assertFalse($cache->useCache()); }
/** * returns the metadata of a page * * @param string $id The id of the page the metadata should be returned from * @param string $key The key of the metdata value that shall be read (by default everything) - separate hierarchies by " " like "date created" * @param int $render If the page should be rendererd - possible values: * METADATA_DONT_RENDER, METADATA_RENDER_USING_SIMPLE_CACHE, METADATA_RENDER_USING_CACHE * METADATA_RENDER_UNLIMITED (also combined with the previous two options), * default: METADATA_RENDER_USING_CACHE * @return mixed The requested metadata fields * * @author Esther Brunner <*****@*****.**> * @author Michael Hamann <*****@*****.**> */ function p_get_metadata($id, $key = '', $render = METADATA_RENDER_USING_CACHE) { global $ID; static $render_count = 0; // track pages that have already been rendered in order to avoid rendering the same page // again static $rendered_pages = array(); // cache the current page // Benchmarking shows the current page's metadata is generally the only page metadata // accessed several times. This may catch a few other pages, but that shouldn't be an issue. $cache = $ID == $id; $meta = p_read_metadata($id, $cache); if (!is_numeric($render)) { if ($render) { $render = METADATA_RENDER_USING_SIMPLE_CACHE; } else { $render = METADATA_DONT_RENDER; } } // prevent recursive calls in the cache static $recursion = false; if (!$recursion && $render != METADATA_DONT_RENDER && !isset($rendered_pages[$id]) && page_exists($id)) { $recursion = true; $cachefile = new cache_renderer($id, wikiFN($id), 'metadata'); $do_render = false; if ($render & METADATA_RENDER_UNLIMITED || $render_count < P_GET_METADATA_RENDER_LIMIT) { if ($render & METADATA_RENDER_USING_SIMPLE_CACHE) { $pagefn = wikiFN($id); $metafn = metaFN($id, '.meta'); if (!@file_exists($metafn) || @filemtime($pagefn) > @filemtime($cachefile->cache)) { $do_render = true; } } elseif (!$cachefile->useCache()) { $do_render = true; } } if ($do_render) { ++$render_count; $rendered_pages[$id] = true; $old_meta = $meta; $meta = p_render_metadata($id, $meta); // only update the file when the metadata has been changed if ($meta == $old_meta || p_save_metadata($id, $meta)) { // store a timestamp in order to make sure that the cachefile is touched $cachefile->storeCache(time()); } elseif ($meta != $old_meta) { msg('Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.', -1); } } $recursion = false; } $val = $meta['current']; // filter by $key foreach (preg_split('/\\s+/', $key, 2, PREG_SPLIT_NO_EMPTY) as $cur_key) { if (!isset($val[$cur_key])) { return null; } $val = $val[$cur_key]; } return $val; }
/** * 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; }
/** * returns the metadata of a page * * @param string $id The id of the page the metadata should be returned from * @param string $key The key of the metdata value that shall be read (by default everything) - separate hierarchies by " " like "date created" * @param boolean $render If the page should be rendererd when the cache can't be used - default true * @return mixed The requested metadata fields * * @author Esther Brunner <*****@*****.**> * @author Michael Hamann <*****@*****.**> */ function p_get_metadata($id, $key = '', $render = true) { global $ID; // cache the current page // Benchmarking shows the current page's metadata is generally the only page metadata // accessed several times. This may catch a few other pages, but that shouldn't be an issue. $cache = $ID == $id; $meta = p_read_metadata($id, $cache); // prevent recursive calls in the cache static $recursion = false; if (!$recursion && $render) { $recursion = true; $cachefile = new cache_renderer($id, wikiFN($id), 'metadata'); if (page_exists($id) && !$cachefile->useCache()) { $old_meta = $meta; $meta = p_render_metadata($id, $meta); // only update the file when the metadata has been changed if ($meta == $old_meta || p_save_metadata($id, $meta)) { // store a timestamp in order to make sure that the cachefile is touched $cachefile->storeCache(time()); } else { msg('Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.', -1); } } $recursion = false; } $val = $meta['current']; // filter by $key foreach (preg_split('/\\s+/', $key, 2, PREG_SPLIT_NO_EMPTY) as $cur_key) { if (!isset($val[$cur_key])) { return null; } $val = $val[$cur_key]; } return $val; }