From: Brion Vibber Date: Fri, 16 May 2003 13:39:22 +0000 (+0000) Subject: Optional server-side caching of anon-viewed pages in filesystem X-Git-Tag: 1.1.0~555 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=a58262c9e76fbd6f48e40aeceeff87725ad3701a;p=lhc%2Fweb%2Fwiklou.git Optional server-side caching of anon-viewed pages in filesystem --- diff --git a/includes/Article.php b/includes/Article.php index 1d0df3bb3b..b438099416 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -289,6 +289,7 @@ class Article { $wgOut->setSubtitle( $s ); } $wgOut->checkLastModified( $this->mTouched ); + $this->tryFileCache(); $wgLinkCache->preFill( $wgTitle ); $wgOut->addWikiText( $text ); @@ -1473,6 +1474,84 @@ name=\"wpSummary\" maxlength=200 size=60>
return $text; } + + + /* Caching functions */ + + function tryFileCache() { + if($this->isFileCacheable()) { + if($this->isFileCacheGood()) { + wfDebug( " tryFileCache() - about to load\n" ); + $this->loadFromFileCache(); + exit; + } else { + wfDebug( " tryFileCache() - starting buffer\n" ); + ob_start( array(&$this, 'saveToFileCache' ) ); + } + } else { + wfDebug( " tryFileCache() - not cacheable\n" ); + } + } + + function isFileCacheable() { + global $wgUser, $wgTitle, $wgUseFileCache, $wgShowIPinHeader; + global $action, $oldid, $diff, $redirect, $printable; + return $wgUseFileCache + and (!$wgShowIPinHeader) + and ($wgUser->getId() == 0) + and (!$wgUser->getNewtalk()) + and ($wgTitle->getNamespace != Namespace::getSpecial()) + and ($action == "view") + and (!isset($oldid)) + and (!isset($diff)) + and (!isset($redirect)) + and (!isset($printable)) + and (!$this->mRedirectedFrom); + + } + + function fileCacheName() { + global $wgTitle, $wgFileCacheDirectory, $wgLang; + $hash = md5( $key = $wgTitle->getDbkey() ); + if( $wgTitle->getNamespace() ) + $key = $wgLang->getNsText( $wgTitle->getNamespace() ) . ":" . $key; + $key = urlencode( $key ); + $hash1 = substr( $hash, 0, 1 ); + $hash2 = substr( $hash, 0, 2 ); + $fn = "{$wgFileCacheDirectory}/{$hash1}/{$hash2}/{$key}.html"; + wfDebug( " fileCacheName() - $fn\n" ); + return $fn; + } + + function isFileCacheGood() { + global $wgUser, $wgCacheEpoch; + if(!file_exists( $fn = $this->fileCacheName() ) ) return false; + $cachetime = wfUnix2Timestamp( filemtime( $fn ) ); + $good = ( $this->mTouched <= $cachetime ) and + $wgUser->validateCache( $cachetime ) and + ($wgCacheEpoch <= $cachetime ); + wfDebug(" isFileCacheGood() - cachetime $cachetime, good $good\n"); + return $good; + } + + function loadFromFileCache() { + wfDebug(" loadFromFileCache()\n"); + readfile($this->fileCacheName()); + } + + function saveToFileCache( $text ) { + # FIXME: assumes directories are already laid out + wfDebug(" saveToFileCache()\n"); + $f = fopen( $this->fileCacheName(), "w" ); + if($f) { + fwrite( $f, str_replace( "", + "\n", + $text ) ); + fclose( $f ); + } + return $text; + } + } ?> diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 1ab6d190fc..56724b29b2 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -45,6 +45,7 @@ $wgEditEncoding = ""; $wgDocType = "-//W3C//DTD HTML 4.01 Transitional//EN"; $wgAmericanDates = false; # Enable for English module to print dates $wgLocalInterwiki = "w"; +$wgShowIPinHeader = true; # For non-logged in users # Miscellaneous configuration settings # @@ -53,7 +54,20 @@ $wgDebugLogFile = "{$wgUploadDirectory}/log_dlJbnMZb"; $wgDebugComments = false; $wgReadOnly = false; -$wgCachePages = true; # Allow client-side caching of pages +# Client-side caching: +$wgCachePages = true; # Allow client-side caching of pages + +# Set this to current time to invalidate all prior cached pages. +# Affects both client- and server-side caching. +$wgCacheEpoch = "20030516000000"; + +# Server-side caching: +# This will cache static pages for non-logged-in users +# to reduce database traffic on public sites. +# Must set $wgShowIPinHeader = false +$wgUseFileCache = false; +$wgFileCacheDirectory = "{$wgUploadDirectory}/cache"; + $wgCookieExpiration = 2592000; $wgAllowExternalImages = true;