Koha-clms/Koha
Jared Camins-Esakov b07f4debb7 Bug 9434: Introduce new tied cache system
At the moment we cache numerous pieces of information in module-level
variables which then do not get updated in other threads/processes when
they are changed by the user. This is a serious usability issue.

Examples of this include the way we treat sysprefs (there is now a
method to disable the syspref cache, but by default it is enabled),
notices, frameworks, field mappings, and koha-conf.xml, at least.

This patch sets the stage for eliminating this problem by making it
possible to convert module-level cache variables into variables that
are actually backed by whatever caching system may be configured. This
is done through a special Koha::Cache::Object class which can be tied
to the variables that are being used for caching and provided with a
constructor method/closure to allow the cache to be reloaded when it
expires. For example:

    my $cache    = Koha::Cache->new();
    my $data     = 'whatever';
    my $variable = Koha::Cache->create_scalar(
        {
            'key'         => 'whatever',
            'timeout'     => 2,
            'constructor' => sub { return $data; },
        }
    );
    print "$$variable\n"; # Prints "whatever"

The one change this necessitates for accessing the data is that the
variable must be dereferenced an additional time before use (i.e.
$$variable instead of $variable). There is no difference when the
variable tied is a hash (created with Koha::Cache->create_hash). This
is a small price to pay for Koha working in a multi-threaded, persistent
environment. This change will also make caching easier in general.

CHI was incompatible with the variable tying, so this patch also removes
the dependency on CHI, using instead Cache::Memcached::Fast,
Cache::FastMmap, and Cache::Memory, when they are available.

To test:
1) Apply patch.
2) Run unit test t/Cache.t (after setting the MEMCACHED_SERVERS and
   CACHING_SYSTEM environment variables). As no changes were made to
   the tests already in that file, this passing demonstrates there
   are no regressions.
3) With memcached caching enabled (you must set the MEMCACHED_SERVERS
   and CACHING_SYSTEM environment variables) and DEBUG turned on (i.e.
   the DEBUG environment variable set to 1), try running a report via
   the web service ([intranet]/cgi-bin/koha/svc/report?id=1 and check
   your web server logs to confirm that there are messages like
   "get_from_cache for intranet:report:id:1" in them.
4) If the reports worked, sign off.

NOTE: Technically you could test this without needing memcached by
installing libcache-fastmmap-perl and setting CACHING_SYSTEM to
'fastmmap' instead of 'memcached'. You could also install libcache-perl
and set CACHING_SYSTEM to 'memory' but there would be little point as
the cached variables would go out of scope in between runs.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
2013-03-20 15:15:44 -04:00
..
Borrower Bug 7067 QA Followup 2012-12-14 08:09:00 -05:00
Cache Bug 9434: Introduce new tied cache system 2013-03-20 15:15:44 -04:00
Filter/MARC Bug 9620: IncludeSeeFromInSearches and data in $9 subfields can break indexing 2013-03-07 09:31:11 -05:00
Indexer Bug 7818: utility to generate DOM indexing configs 2012-06-09 11:44:00 +02:00
Plugins Bug 7804 - Add Koha Plugin System - QA Followup 3 - Additional Unit Tests 2013-03-20 14:50:38 -04:00
QueryParser/Driver Bug 9239 QA follow-up: fix overeager quote escaping 2013-03-16 21:32:35 -04:00
RecordProcessor Bug 7417: Include see from references in bibliographic searches 2012-09-13 14:19:28 +02:00
SearchEngine Bug 9727: Fix typo in variable name 2013-03-19 20:48:25 -04:00
SuggestionEngine Bug 9239: Allow the use of QueryParser for all queries 2013-03-16 21:32:32 -04:00
Template/Plugin Follow-up Bug 7387 - Add Template::Toolkit plugin to allow caching of includes 2013-03-07 10:58:52 -05:00
Authority.pm Bug 7417 follow-up: fix a perlcritic violation 2012-09-14 17:22:11 +02:00
Cache.pm Bug 9434: Introduce new tied cache system 2013-03-20 15:15:44 -04:00
Calendar.pm Bug 9211 - days_between wrong behaviour 2013-01-24 09:56:37 -05:00
DateUtils.pm Bug 8652: Followup: add a default value for date_from 2012-10-09 11:27:42 +02:00
Linktracker.pm Bug 8917 : [ Sign followup ] Track clicks to links external to Koha 2013-03-07 11:14:25 -05:00
Plugins.pm Bug 7804 - Add Koha Plugin System - QA Followup 2 2013-03-20 14:50:19 -04:00
RecordProcessor.pm Bug 7417: Include see from references in bibliographic searches 2012-09-13 14:19:28 +02:00
SearchEngine.pm Bug 8233 : SearchEngine: Add a Koha::SearchEngine module 2012-07-06 16:51:58 +02:00
SuggestionEngine.pm Bug 8726: ExplodedTerms suggestion plugin (functionality) 2012-09-28 17:08:21 +02:00