TWiki Guest Cache Add-On
Speed up a TWiki site by caching topics for non-authenticated users
Overview
Public TWiki sites are frequently visited by search engine spiders and non-authenticated users. The actual traffic by authenticated users who browse and change content is typically less than 5% of all traffic. This add-on is designed to cache topics for non-authenticated users. Content is not cached for authenticated users - this ensures that personalized content remains personalized.
A typical TWiki page may load in about 1 second. A cached topic loads about 10 times faster.
Deploying this add-on on a public TWiki site tends to speed up the site for all users. It also reduces the CPU load considerably on a high traffic site. On TWiki.org the average CPU load dropped from 2-3 down to 0.2-0.5 after deploying this add-on.
Cache Algorithm
Once the add-on is installed and configured it can be forgotten, the caching and cache update is done automatically.
A topic is only cached if:
- the user is not authenticated,
- the requested URL has no parameters,
- the requested topic exists,
- the topic is not on the exclusion list.
The cached content is returned if all conditions are met and if the cache exists. If needed, a topic is cached or re-cached first.
A configurable cache invalidation determines when a topic is re-cached. There are three tiers:
- Tier 1 topics, such as
WebChanges, WebRss
: Cache invalidation is 1 hour by default.
- Tier 2 topics, such as
WebHome, WebTopicList
: Cache invalidation is 6 hours by default.
- Other topics: Cache invalidation is 48 hours by default.
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 TWiki server.
- For an automated installation, run the configure script and follow "Find More Extensions" in the in the Extensions section.
- Or, follow these manual installation steps:
- Download the ZIP file from the Plugins home (see below).
- Unzip
TWikiGuestCacheAddOn.zip
in your twiki installation directory. Content: File: | Description: |
data/TWiki/TWikiGuestCacheAddOn.txt | Add-on topic |
bin/viewcache | View script with cache logic |
lib/TWiki/Contrib/TWikiGuestCacheAddOn.pm | Add-on Perl module |
lib/TWiki/Contrib/TWikiGuestCacheAddOn/Config.spec | Spec file for configure |
- Set the ownership of the extracted directories and files to the webserver user.
- Add-on configuration and testing:
- Configure the TWikiGuestCacheAddOn settings in the Extensions section.
- Settings:
# Comma-space delimited list of topic names to exclude:
$TWiki::cfg{TWikiGuestCacheAddOn}{ExcludeTopics} = 'TWikiRegistration';
# Comma-space delimited list of tier 1 topic names:
$TWiki::cfg{TWikiGuestCacheAddOn}{Tier1Topics} = 'WebAtom, WebChanges, WebRss';
# Maximum cache age for tier 1 pages, in hours:
$TWiki::cfg{TWikiGuestCacheAddOn}{Tier1CacheAge} = '1';
# Comma-space delimited list of tier 2 topic names:
$TWiki::cfg{TWikiGuestCacheAddOn}{Tier2Topics} = 'WebHome, WebTopicList';
# Maximum cache age for tier 2 pages, in hours:
$TWiki::cfg{TWikiGuestCacheAddOn}{Tier2CacheAge} = '6';
# Maximum cache age for default pages, in hours:
$TWiki::cfg{TWikiGuestCacheAddOn}{CacheAge} = '48';
# Debug flag:
$TWiki::cfg{TWikiGuestCacheAddOn}{Debug} = 0;
- Copy the
twiki/bin/viewcache
script to twiki/bin/view
(overwrite the latter).
- Test if the installation was successful:
- Logout and view a topic as a not authenticated user.
- On the shell, check if the cache file
twiki/pub/.cache/<web>/<topic>.html
has been created.
- The second time you view a topic, it should load much faster.
- Look at the tail of the TWiki log file
twiki/data/log202505.txt
to verify that cached content is returned you should see "from cache"
entries. Example:
| 2025-05-12 - 16:40 | guest | view | Support.SupportForum | Mozilla - from cache | 1.2.3.4 |
Add-On Info
- Set SHORTDESCRIPTION = Speed up a TWiki site by caching topics for non-authenticated users
Related Topic: TWikiAddOns