Caching services for Foswiki extensions
This package is used by other extensions in need of caching services. This specific cache stores data
for a short period time, e.g. one day, for faster access in the meantime. Data might be any arbitrary
perl data object which is serialized by the underlying cache implementation CHI - Unified cache handling interface
CHI offers some interesting features such as multi-level caching, shared caching and distributed caching
based on the configuration. It thus is suitable to share cached data among several Foswiki backends, either on the same host
or in a distributed setup.
Interface to the caching services. This consists of two parts:
- basic caching: cache computational results for a short period of time for faster access
- a caching user agent: fetch external resources and cache them
Both of these requirements happen so often in Foswiki plugins that they have been provided as
a basic service to be accessed by third party plugins. For instance, ImagePlugin caches
image geometries as analysing and extracting this information from pictures can be quite expensive.
NumberPlugin fetches exchange rates of currencies from an external provider and caches them locally.
FeedPlugin fetches RSS and Atom feeds and caches them locally when rerendering them on a Foswiki page.
SolrPlugin serializes binary document formats while indexing their content with interim results cached
locally to speed up reindexing those documents.
getUserAgent() -> $ua
returns a singleton caching user agent compatible to CPAN:LWP::UserAgent
Note, the returned user agent uses a cache in the fixed namespace "UserAgent". So you
might access its cache via
Cache entries are using the URL of the external resource being fetched. See also
getCache($namespace) -> $cache
returns a CHI cache object
for the given namespace.
my $cache = Foswiki::Contrib::CacheContrib::getCache("ImagePlugin");
getExternalResource($url, ...) -> $response
Fetch an external resource using the caching UserAgent. This is equivalent
with just adding caching.
It basically is compatible with
my $response = Foswiki::Contrib::CacheContrib::getExternalResource($url);
throw Error::Simple("http error fetching $url: ".$response->code." - ".$response->status_line)
my $content = $response->decoded_content();
clears the cache for the given namespace
purges expired entries of the cache for the given namespace
Clearing and Purging the cache
The cache can be cleared or purged using a separate tool that is best installed as a cronjob to perform these
maintenance steps offline on a regular base.
purgeCache: purge outdated cache entries as configured in the
clearCache: clear all of the cache independently of its expiry time
virtualhosts-clearCache: same scripts as above but to be used in a virtual hosting environment
CacheContrib implements a caching user agent ontop of the regular LWP::UserAgent. This can either be instanciated using the
or by directly creating an object of the class
. The default caching namespace for both is
, that is all instances share
the same cache. The
cache may be purged individually using the url parameter
For convenience there is a caching variat of the standard API
behaves the same but except:
- uses proper proxy settings
- uses LWP::UserAgent for any network interaction
- uses caching
You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.
Open configure, and open the "Extensions" section. "Extensions Operation and Maintenance" Tab -> "Install, Update or Remove extensions" Tab. Click the "Search for Extensions" button.
Enter part of the extension name or description and press search. Select the desired extension(s) and click install. If an extension is already installed, it will not
show up in the
You can also install from the shell by running the extension installer as the web server user: (Be sure to run as the webserver user, not as root!)
perl tools/extension_installer <NameOfExtension> install
If you have any problems, or if the extension isn't available in
, then you can still install manually from the command-line. See https://foswiki.org/Support/ManuallyInstallingExtensions
for more help.
| 14 Oct 2020
|| initial release