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:
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.
namespace
(defaults to "UserAgent") parameter defines the cache section used for this agent.
my $cache = Foswiki::Contrib::CacheContrib::getCache("ImagePlugin");
Foswiki::Func::getExternalResource()
with just adding caching.
It basically is compatible with LWP::UserAgent::get
.
Usage:
my $response = Foswiki::Contrib::CacheContrib::getExternalResource($url); throw Error::Simple("http error fetching $url: ".$response->code." - ".$response->status_line) unless $response->is_success; my $content = $response->decoded_content();
clears the cache for the given namespace
purges expired entries of the cache for the given namespace
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 $Foswiki::cfg{CacheContrib}{CacheExpire}
setting
clearCache
: clear all of the cache independently of its expiry time
virtualhosts-pureCache
, virtualhosts-clearCache
: same scripts as above but to be used in a virtual hosting environment
Foswiki::Contrib::CacheContrib::getUserAgent()
api
or by directly creating an object of the class Foswiki::Contrib::CacheContrib::UserAgent
. The default caching namespace for both is UserAgent
, that is all instances share
the same cache. The UserAgent
cache may be purged individually using the url parameter refresh=on
or refresh=ua
.
For convenience there is a caching variat of the standard API Foswiki::Func::getExternalResource
available at Foswiki::Contrib::CacheContrib::getExternalResource
which basically
behaves the same but except:
cd /path/to/foswiki perl tools/extension_installer <NameOfExtension> installIf you have any problems, or if the extension isn't available in
configure
, then you can still install manually from the command-line. See https://foswiki.org/Support/ManuallyInstallingExtensions for more help.
Name | Version | Description |
---|---|---|
LWP::UserAgent | >=0 | Required |
CHI | >=0 | Required |
27 Apr 2022 | add support for multiple namespaces and cache agents; improve handling of per cache expiry parameters |
14 Oct 2020 | initial release |
Author | Michael Daum |
Version | 3.00 |
Release | 17 Mar 2022 |
Description | Caching services for Foswiki extensions |
Repository | https://github.com/foswiki/CacheContrib |
Copyright | 2020-2022, Michael Daum, All Rights Reserved |
License | GPL (GNU General Public License) |
Home | http://foswiki.org/Extensions/CacheContrib |
Support | http://foswiki.org/Support/CacheContrib |