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



NAME

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


SYNOPSIS

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


DESCRIPTION

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


CONSTRUCTOR OPTIONS

When using this driver, the following options can be passed to CHI->new() in addition to the CHI.


=over
subcaches [ARRAYREF]

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.


OPERATION

This section describes how the standard CHI methods are interpreted for multilevel caches.

get

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.

get_object
get_expires_at

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

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).

remove
clear

Calls the method on each subcache.

get_keys
get_namespaces

Calls the method on all subcaches and returns the union of the results.


AUTHOR

Jonathan Swartz


COPYRIGHT & LICENSE

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.

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