
CHI::Driver::Multilevel -- Use several caches chained together

use CHI;
my $cache = CHI->new(
driver => 'Multilevel',
subcaches => [
{ driver => 'Memory' },
{
driver => 'Memcached',
servers => [ "10.0.0.15:11211", "10.0.0.15:11212" ]
}
],
);

This cache driver allows you to use two or more CHI caches together, for example, a memcached cache bolstered by a local memory cache.

When using this driver, the following options can be passed to CHI->new() in addition to the CHI.
Required - an array reference of CHI caches that will power this cache, in order from most to least local. Each element of the array is either a hash reference to be passed to CHI->new(), or an actual driver handle.
The accessor of the same name will return an array reference of driver handles.
The namespace option will automatically be passed to subcaches. Right now, expiration options are only supported in the parent cache - subcaches currently may not have different expiration options.

This section describes how the standard CHI methods are interpreted for multilevel caches.
Do a get from each subcache in turn, returning the first defined and unexpired value found. In addition, set the value in any more-local subcaches that initially missed, using the subcache's default set options.
For example, in our memory-memcached example, a hit from the memcached cache would cause the value to be written into the memory cache, but a hit from the memory cache would not result in a write to the memcached cache.
Calls the method on each subcache in turn, returning the first defined value found. These methods are not very well suited to multilevel caches; you might be better off calling these methods manually on the individual subcache handles.
Set the value in all subcaches (write-through). Expiration options are taken from the set() method, then from the default options for the parent cache. Subcaches may not have their own default expiration options (this may change in the future).
Calls the method on each subcache.
Calls the method on all subcaches and returns the union of the results.

Jonathan Swartz

Copyright (C) 2007 Jonathan Swartz.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.