This patch for enable to cache contents of page only (not cache template).
1. To install you need aplied this patch:
diff -Naur tavi-0.22/action/admin.php tavi-cache/action/admin.php
--- tavi-0.22/action/admin.php 2002-11-11 11:55:08.000000000 +0900
+++ tavi-cache/action/admin.php 2002-11-11 11:57:10.000000000 +0900
@@ -27,6 +27,11 @@
else
{ $blocking = $HTTP_POST_VARS['blocking']; }
+if(isset($HTTP_GET_VARS['clearcache']))
+ { $clearcache = $HTTP_GET_VARS['clearcache']; }
+else
+ { $clearcache = $HTTP_POST_VARS['clearcache']; }
+
$Block = isset($HTTP_POST_VARS['Block'])
? $HTTP_POST_VARS['Block'] : '';
$Unblock = isset($HTTP_POST_VARS['Unblock'])
@@ -123,11 +128,46 @@
header('Location: ' . $AdminScript);
}
}
+else if($clearcache)
+{
+ if(empty($ClearCache) ) // Not saving results; display form.
+ {
+ $html = "<h3>Cached files:</h3>";
+ $d = dir($cachedir);
+ while (false !== ($entry = $d->read())) {
+ if (is_file($cachedir.'/'.$entry) ) {
+ $html .= $entry."<br>\n";
+ }
+ }
+ $d->close();
+ $html .= "<form action=\"$AdminScript?clearcache=1\" method=post>
+ <input type=submit name=ClearCache value=\"Clear cache!\"></form>";
+ template_admin(array('html' => $html));
+ }
+ else // admin function
+ {
+ $d = dir($cachedir);
+ while (false !== ($entry = $d->read())) {
+ if (is_file($cachedir.'/'.$entry) ) {
+ if (@unlink($cachedir.'/'.$entry)) {
+ $html .= $entry." <b>deleted!</b><br>\n";
+ } else {
+ $html .= $entry." <b>can't delete!</b><br>\n";
+ }
+ }
+ }
+ $d->close();
+ template_admin(array('html' => $html));
+ }
+}
else // Display main menu for admin.
{
template_admin(array('html' => html_url($AdminScript . '?locking=1',
'Lock / unlock pages') .
html_newline() .
+ html_url($AdminScript . '?clearcache=1',
+ 'Clear cached files') .
+ html_newline() .
html_url($AdminScript . '?blocking=1',
'Block / unblock hosts') .
html_newline()));
diff -Naur tavi-0.22/action/save.php tavi-cache/action/save.php
--- tavi-0.22/action/save.php 2002-10-21 01:03:02.000000000 +1000
+++ tavi-cache/action/save.php 2002-11-11 12:17:30.000000000 +0900
@@ -67,6 +67,7 @@
add_to_category($page, $categories);
}
+ $pagestore->update_cache_flag($page);
template_save(array('page' => $page,
'text' => $document));
diff -Naur tavi-0.22/action/view.php tavi-cache/action/view.php
--- tavi-0.22/action/view.php 2002-01-08 01:28:32.000000000 +0900
+++ tavi-cache/action/view.php 2002-11-11 11:58:38.000000000 +0900
@@ -11,6 +11,7 @@
function action_view()
{
global $page, $pagestore, $ParseEngine, $version;
+ global $cachedir, $use_cache, $no_cache_pages;
$pg = $pagestore->page($page);
if($version != '')
@@ -18,12 +19,32 @@
$pg->read();
gen_headers($pg->time);
-
- template_view(array('page' => $page,
- 'html' => parseText($pg->text, $ParseEngine, $page),
- 'editable' => $pg->mutable,
- 'timestamp' => $pg->time,
- 'archive' => $version != '',
- 'version' => $pg->version));
+ $topic = rawurlencode($page);
+ $cachefile="$cachedir/$topic.html";
+ $need_recache = $pg->need_recache();
+ $page_time=mktime(substr($pg->time,8,2),substr($pg->time,10,2),substr($pg->time,12,2),substr($pg->time,4,2),substr($pg->time,6,2),substr($pg->time,0,4));
+ $we_can_use_cache=((!in_array($page,$no_cache_pages))&&($pg->exists())&&($use_cache==1)&&($version == ''));
+ if (($we_can_use_cache)&&(is_file($cachefile))&&($page_time<filemtime($cachefile))&&(!$need_recache)) {
+ // alredy cached
+ $fp=fopen($cachefile,"r");
+ $content = fread($fp, filesize ($cachefile));
+ fclose($fp);
+ }elseif (($we_can_use_cache)) {
+ // need to cache
+ $content=parseText($pg->text, $ParseEngine, $page);
+ $pg->UnSetNeedRecache();
+ $fp=fopen($cachefile,"w");
+ fwrite($fp,$content);
+ fclose($fp);
+ }else {
+ // no need to cache
+ $content=parseText($pg->text, $ParseEngine, $page);
+ }
+ template_view(array('page' => $page,
+ 'html' => $content,
+ 'editable' => $pg->mutable,
+ 'timestamp' => $pg->time,
+ 'archive' => $version != '',
+ 'version' => $pg->version));
}
?>
diff -Naur tavi-0.22/config.php tavi-cache/config.php
--- tavi-0.22/config.php 1970-01-01 09:00:00.000000000 +0900
+++ tavi-cache/config.php 2002-11-11 12:37:30.000000000 +0900
@@ -0,0 +1,10 @@
+$TAVIPATH = dirname(__FILE__).'/';
+if (eregi("WIN",PHP_OS)) {
+ $TAVIPATH = str_replace("\\","/",$TAVIPATH);
+}
+$cachedir = $TAVIPATH . 'cache'; // full path to cache dir without trailing slash
+$use_cache = 1; //1 enable cache, 0 disable
+
+// ARRAY of pages not need to cache
+$no_cache_pages = array('RecentChanges','PageSize','LinkTable','OrphanedPages',
+'WantedPages','PageLinks','PageRefs','EmptyPages','NewPages');
diff -Naur tavi-0.22/lib/page.php tavi-cache/lib/page.php
--- tavi-0.22/lib/page.php 2001-12-01 07:10:16.000000000 +0900
+++ tavi-cache/lib/page.php 2002-11-11 12:11:06.000000000 +0900
@@ -24,6 +24,41 @@
$this->dbname = str_replace('\'', '\\\'', $this->dbname);
}
+ // return true if need_recache==1
+ function need_recache()
+ {
+ global $PgTbl;
+ $qid = $this->db->query("SELECT count(*) FROM $PgTbl " .
+ "WHERE title='$this->dbname' AND need_recache='1'");
+ $result = $this->db->result($qid);
+ return (($result[0]>0));
+ }
+
+ // Set need_recache flag
+ function SetNeedRecache()
+ {
+ global $PgTbl;
+ if ($this->exists()) {
+ $qid = $this->db->query("SELECT time FROM $PgTbl " .
+ "WHERE title='$this->dbname' ORDER BY version DESC LIMIT 1");
+ $result = $this->db->result($qid);
+ $this->db->query("UPDATE $PgTbl SET time = '$result[0]', need_recache=1 " .
+ "WHERE title='$this->dbname' " );
+ }
+ }
+ // UnSet need_recache flag
+ function UnSetNeedRecache()
+ {
+ global $PgTbl;
+ if ($this->exists()) {
+ $qid = $this->db->query("SELECT time FROM $PgTbl " .
+ "WHERE title='$this->dbname' ORDER BY version DESC LIMIT 1");
+ $result = $this->db->result($qid);
+ $this->db->query("UPDATE $PgTbl SET time = '$result[0]', need_recache=0 " .
+ "WHERE title='$this->dbname' " );
+ }
+ }
+
// Check whether a page exists.
// Returns: nonzero if page exists in database.
diff -Naur tavi-0.22/lib/pagestore.php tavi-cache/lib/pagestore.php
--- tavi-0.22/lib/pagestore.php 2002-11-11 12:15:26.000000000 +0900
+++ tavi-cache/lib/pagestore.php 2002-11-11 12:20:38.000000000 +0900
@@ -67,6 +67,16 @@
return $list;
}
+ // update need_recache flag for pages witch linking to $page
+ function update_cache_flag($page) {
+ global $LkTbl;
+ $qid = $this->dbh->query("SELECT page FROM $LkTbl WHERE link='".addslashes($page)."'");
+ while(($row = $this->dbh->result($qid))) {
+ $p = $this->page($row[0]);
+ $p->SetNeedRecache();
+ }
+ }
+
// Look up an interwiki prefix.
function interwiki($name)
{
diff -Naur tavi-0.22/upgrade_tavi_to_cache.php tavi-cache/upgrade_tavi_to_cache.php
--- tavi-0.22/upgrade_tavi_to_cache.php 1970-01-01 09:00:00.000000000 +0900
+++ tavi-cache/upgrade_tavi_to_cache.php 2002-11-11 12:29:10.000000000 +0900
@@ -0,0 +1,11 @@
+<?
+include ('config.php');
+if (!$dbi=mysql_connect(DBServer, $DBUser, $DBPasswd))
+ { die('MySQL Error: '.mysql_error()); }
+
+if (!mysql_select_db($DBName, $dbi))
+ { die('MySQL Error: '.mysql_error()); }
+$query = 'ALTER TABLE `tavi_pages` ADD `need_recache` TINYINT DEFAULT '0' NOT NULL AFTER `supercede`';
+if(!($qid = mysql_query($query, $dbi)))
+ { die('MySQL Error: '.mysql_error()); }
+?>
2. in config.php you need to change:
$cachedir = '/path/to/tavi/cache'; // full path to cache dir without trailing slash
$use_cache = 1 ; //1 enable cache, 0 disable
// ARRAY of pages not need to cache
$no_cache_pages = array('RecentChanges','PageSize','LinkTable','OrphanedPages',
'WantedPages','PageLinks','PageRefs','EmptyPages','NewPages');
$cachedir - need CHMOD this dir to "0777"
3. execute upgrade_tavi_to_cache.php, example http://localhost/tavi/upgrade_tavi_to_cache.php
That's all folks!