[Pmwiki-users] Cache system with PmWiki
Alexandre Courbot
Alexandre.Courbot
Thu Sep 9 13:55:38 CDT 2004
Hello everybody,
A friend of mine has written a simple, yet efficient cache system for
pmwiki 1.0.8 (the existing ones weren't what we expected, so he decided
to write his own). We're running into a slight problem however:
password-protected pages are displayed without any authentication if
cached. Basically we redirected HandleActions["browse"] to our own
function which looks like this:
function SmartCacheHandleBrowse($PageName)
{
global $EnableSmartCache, $PmWikiBrowseAction;
if (!$EnableSmartCache)
return $PmWikiBrowseAction($PageName);
// first check if the cache dir exists and if not, creates it
if (!CheckAndCreateCacheDir())
return CreatePageCache($PageName); // must create the page cache
since it is the first call
if (!AdditionalFilesAreUpToDate())
InvalidateCache("");
// check if all is up to date
if (!PageIsUpToDate($PageName))
return CreatePageCache($PageName);
// the page is up to date, return the cached version
return GetCachedPage($PageName);
}
And GetCachedPage:
function GetCachedPage($PageName)
{
global $DebugSmartCache;
$cache_file = GetCacheFile($PageName);
$file_content = file($cache_file);
if (!$file_content)
return CreatePageCache($PageName);
$content = implode("", $file_content);
if ($DebugSmartCache)
$content = str_replace("</title>", " [From Cache]</title>",
$content);
print $content;
return true;
}
I fail to see how we could integrate authentication here. Actually I
fail to understand how the authentication works exactly. Could someone
give a pointer?
Also, I'd like to discuss some of the cache issues. There are lots of
them (others pages the page being visited depends on, etc.), but I
wonder if most of them couldn't be workarounded in PmWiki 2.0 by good
design. Like, a page file could contain all the pages it depends on -
and extensions could be provided a mechanism to register new
dependancies. All in all the reason that motivated our cache was the
general slowness of our site once switched to PmWiki, because it has
some large, loaded pages and uses lots of extensions. This is a general
problem with PHP since it doesn't have a compiled form (not even
bytecode like Python) and at some point a site will face service issues
when using too much extensions. Are there plans in 2.0 to deal with
these problems? Are there tips to improve the general speed of the site?
Thanks,
Alex.
More information about the pmwiki-users
mailing list