internal package
Foswiki::Contrib::DBCacheContrib
General purpose cache that presents Foswiki topics as expanded hashes
Useful for rapid read and search of the database. Only works on one web.
Typical usage:
use Foswiki::Contrib::DBCacheContrib;
$db = new Foswiki::Contrib::DBCacheContrib( $web ); # always done
$db->load(); # may be always done, or only on demand when a tag is parsed that needs it
# the DB is a hash of topics keyed on their name
foreach my $topic ($db->getKeys()) {
my $attachments = $db->fastget($topic)->fastget("attachments");
# attachments is an array
foreach my $val ($attachments->getValues()) {
my $aname = $attachments->fastget("name");
my $acomment = $attachments->fastget("comment");
my $adate = $attachments->fastget("date");
...
}
}
As topics are loaded, the readTopicLine method gives subclasses an opportunity
to apply special processing to indivual lines, for example to extract special
syntax such as %ACTION lines, or embedded tables in the text. See
FormQueryPlugin for an example of this.
new($web, $cacheName[, $standardSchema ])
Construct a new DBCache object.
-
$web
name of web to create the object for.
-
$cacheName
name of cache file
-
$standardSchema
Set to 1 this will load the cache using the 'standard' Foswiki schema, rather than the original DBCacheContrib extended schema.
- $topic - name of the topic being read
- $meta - reference to the hash object for this topic
- line - the line being read
- $lines - reference to array of remaining lines after the current line
The function may modify $lines to cause the caller to skip lines.
onReload($topics)
-
$topics
- perl array of topic names that have just been loaded (or reloaded)
Designed to be overridden by subclasses. Called when one or more topics had to be
read from disc rather than from the cache. Passed a list of topic names that have been read.
load( [updateCache] ) → ($readFromCache, $readFromFile, $removed)
Load the web into the database.
Returns a list containing 3 numbers that give the number of topics
read from the cache, the number read from file, and the number of previously
cached topics that have been removed.
uptodate($topic, $time)
→ boolean
Check the file time against what is seen on disc. Return 1 if consistent, 0 if inconsistent.
parseDate($string)
→ epoch
try as hard as possible to parse the string into epoch seconds