TWiki Cache Add-On
This add-on allows you to cache pages in TWiki and, with smart algorithm :-)), almost always gives you the latest version of page.
Well, because our TWiki grows very fast and the response from our server was slower and slower, we need some cache mechanism to relieve the server. I tried to use
CacheAddOn but it doesn't work as I need. The biggest problem was that we use authentication for all operations in TWiki and we use modified version of
KoalaSkin, where users can modify many things by their needs. It means that caching pages for all users in one place wasn't possible because the rendered HTML page was different for every user.
That's why I created my own caching mechanism. The caching algorithm works in this way. It starts
view script and search cache directory. If it finds a cached HTML page then the algorithm checks these conditions:
- is cached page newer than topic
- is cached page newer than included topics
- contains topic %SEARCH% or %ACTIONSEARCH% (depends on CACHESEARCH variable)
- is cached page newer than generated templates (if KoalaSkin is enabled)
If these conditions are fulfilled then the cached page is returned else the page is rendered as normal and is cached for later use. The next problem I found with
CacheAddOn was when I try to see topic in some revision, sort tables, use
SlideShowPlugin etc. In my version it works OK. It means that you should in every case get the latest version of the page.
The algorithm doesn't check any changes in user preferences that affect rendering of TWiki pages.
There are two possibilities to solve this problem:
- use refreshing
- clean the cache and start caching from scratch
In our TWiki I add to the
view template 'Refresh' button that points to the same topic with parametr 'nocache=on' (for example for actual topic it is: https://twiki.org/cgi-bin/view/Plugins/TWikiCacheAddOn?nocache=on).
Then I add to the
oopsmore template the possibility to clean the cache (add link to: https://twiki.org/cgi-bin/cache). If you use per user cache then each user can clean only his/her cache.
Usage
Administrator setting
You
have to set up these variables in TWiki.cfg file in
lib directory:
| $cacheDir |
directory where the generated HTML files will be stored |
| $useCache |
this allows to use caching in TWiki (default: "0") |
| $usePerUserCache |
this enables per user caching. If you have restricted access to view script and users use different skins you have to set this variable to "1" because the generated page is different for every user. (default: "0") |
| $cacheGroup |
set group name which should be owner of created files (default: "") |
| $cacheFileRights |
set UNIX rights for created files (default: 0777) |
| $cacheDirRights |
set UNIX rights for created directories (default: 0777) |
!!! YOU HAVE TO SET UP AT LEAST $cacheDir VARIABLE !!! The others are set to default values if not set.
Note: When you set
useCache variable to "1" it doesn't mean that caching is enabled (it only allows to administrator disallow caching if he needs). If you want to cache pages of all users you have to set USECACHE variable to "on" in
TWikiPreferences topic. Else each user can specify in his user-topic if he wants to use caching or not (USECACHE = on/off).
User setting
You can use these variables to set caching by your needs:
| USECACHE |
on/off |
this allows you to cache TWiki pages (default: off) |
| CACHESEARCH |
on/off |
this allows to cache pages with SEARCH (default: off) |
Note: Now it checks %SEARCH% and %ACTIONSEARCH% variables as topics with search. If you use any other search variables you need to modify the view script.
Add-On Installation Instructions
Note: You do not need to install anything on the browser to use this add-on. The following instructions are for the administrator who installs the add-on on the server where TWiki is running.
- Download the ZIP file from the Add-on Home (see below)
- Unzip
TWikiCacheAddOn.zip in your twiki installation directory. Content: | File: | Description: |
bin/view | 'view' script with caching possibility |
bin/cache | 'cache' script for cleaning the cache if needed |
Note: Of course, don't forget to backup your current view script in case my script will not work!!!
Add-On Info
- Set SHORTDESCRIPTION = Cache pages in TWiki for better performance
Related Topic: TWikiAddOns
This work was sponsored by
Systinet Corp.
--
RichardBaar - 27 Aug 2003