NAME

CWB::Web::Cache - A simple shared cache for CQP query results

SYNOPSIS

use CWB::CQP;
use CWB::Web::Cache;

$cqp = new CWB::CQP;
$cache = new CWB::Web::Cache -cqp => $cqp, -cachedir => $dir,
  [-cachesize => $cache_size,] [-cachetime => $expiration_time];

# transparently execute and cache simple CQP queries
$id = $cache->query(-corpus => "DICKENS", -query => '[pos="NN"] "of" "England"');
($size) = $cqp->exec("size $id");

# optional features: sort clause, set keyword, subquery, and maximal number of matches
$id = $cache->query(
  -corpus => "DICKENS", -query => $query,
  -sort => $sort_clause,
  -keyword => $set_keyword_command,
  -subquery => $subquery,
  -cut => $max_nr_of_matches  # resonable default calculated from cache size
);


## The functions below are for internal use only and subject to change in future releases!
$id = $cache->store("DICKENS:Query1");        # activates DICKENS corpus
$id = $cache->store("DICKENS:Query1", "Metadata line #1", ...);

$size = $cache->retrieve($id);                # (re-)activates DICKENS corpus
die 'Sorry, named query has expired from the cache.'
  unless defined $size;
$cqp->exec("Query1 = $id");                   # copy query result to desired name

$id = $cache->retrieve("DICKENS:Query", "Metadata line #1", ...);
die 'Sorry, no named query matching your metadata found in cache.'
  unless defined $id;
$cqp->exec("Query = $id");

DESCRIPTION

The CWB::Web::Cache module provides a simple shared caching meachnism for CQP query results, making them persistent across multiple CQP sessions. Old data files are automatically deleted when they pass the specified $expiration_time, or to keep the cache from growing beyond the specified $cache_size limit.

Note that a CWB::Web::Cache handle must be created with a pre-initialised CQP backend (i.e. a CWB::CQP object), which will be used to access the cache and (re-)run a query when necessary.

Most scripts will access the cache through the query() method, which executes and caches CQP queries in a fully transparent way (with optional sort clause, set keyword command, subquery, and cut to limit the maximal number of matches). After successful execution, the query result is loaded into the CQP backend, the appropriate corpus is activated, and the $id of the named query is returned.

The sort clause is executed after a set keyword command so that keyword anchors can be used in sorting.

Direct access to cache entries is provided by the low-level methods store() and retrieve(). Note that these are intended for internal use only and may change in future releases.

METHODS

TODO

COPYRIGHT

Copyright (C) 1999-2022 Stephanie Evert [http::/purl.org/stephanie.evert]

This software is provided AS IS and the author makes no warranty as to its use and performance. You may use the software, redistribute and modify it under the same terms as Perl itself.