NAME
Cache::Cascade - Get/set values to/from a group of caches, with some advanced semantics.
VERSION
version 0.07
SYNOPSIS
use Cache::Cascade;
Cache::Cascade->new(
caches => [
Cache::Bounded->new(...),
Cache::FastMmap->new(...),
Cache::Memcached->new(...),
],
float_hits => 1,
set_deep => 1,
);
DESCRIPTION
In a multiprocess, and especially a multiserver application caching is a very effective means of improving results.
The tradeoff of increasing the scale of the caching is in added complexity. For example, caching in a FastMmap based storage is much slower than using a memory based cache, because pages must be locked to ensure that no corruption will happen. Likewise Memcached is even more overhead than FastMmap because it is network bound, and uses blocking IO (on the client side).
This module attempts to make a transparent cascade of caches using several backends.
The idea is to search from the cheapest backend to the most expensive, and depending on the options also cache results in the cheaper backends.
The benefits of using a cascade are that if the chance of a hit is much higher in a slow cache, but checking a cheap cache is negligible in comparison, we may already have the result we want in the cheap cache. Configure your expiration policy so that there is approximately an order of magnitude better probability of cache hits (bigger cache) for each level of the cascade.
FIELDS
- set_deep
-
Defaults to true. See
set. - float_hits
-
Defaults to false. See
get.
METHODS
- get $key
-
This method will delegate
getto every cache object in order, and return the first match.Additionally, if
float_hitsis set to a true value, it will also callsetwith the match on every cache object before the one that matched. - set $key, $value
-
If
set_deepis set to a true value this method will delegatesetto every cache object in the list.If
set_deepis set to a false value this method will delegatesetjust to the first cache object in the list. - remove $key
- clear
-
These methods will delegate
removeon every cache object in the list. - entry $key
- exists $key
-
Returns the first match.
- clear
- size
- count
-
These two methods are sum based aggregates.
- validate_callback
- load_callback
-
These two methods return the first callback they found.
- set_load_callback
- set_validate_callback
-
These two methods set the callback for all the caches.
- get_and_float_result $key, @caches
-
This is used to implement the
float_hitsbehavior ofgetrecursively.
CAVEATS
When you set or remove a key from the cascade and this propagates downwards, for example from MemoryCache to FastMmap, other cascades will not notice the change until their own MemoryCache is expired.
Thus, if cache invalidation is important in your algorithm (data changes) do not use a cascade. If stale hits are permitted, or the cache is for non changing data then you should use a cascade.
SEE ALSO
SUPPORT
Bugs may be submitted through the RT bug tracker (or bug-Cache-Cascade@rt.cpan.org).
AUTHOR
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
CONTRIBUTOR
Karen Etheridge <ether@cpan.org>
COPYRIGHT AND LICENCE
This software is copyright (c) 2006 by יובל קוג'מן (Yuval Kogman).
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.