Cache::Cascade - Get/set values to/from a group of caches, with some advanced semantics.
version 0.07
use Cache::Cascade; Cache::Cascade->new( caches => [ Cache::Bounded->new(...), Cache::FastMmap->new(...), Cache::Memcached->new(...), ], float_hits => 1, set_deep => 1, );
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.
Defaults to true. See set.
set
Defaults to false. See get.
get
This method will delegate get to every cache object in order, and return the first match.
Additionally, if float_hits is set to a true value, it will also call set with the match on every cache object before the one that matched.
float_hits
If set_deep is set to a true value this method will delegate set to every cache object in the list.
set_deep
If set_deep is set to a false value this method will delegate set just to the first cache object in the list.
These methods will delegate remove on every cache object in the list.
remove
Returns the first match.
These two methods are sum based aggregates.
These two methods return the first callback they found.
These two methods set the callback for all the caches.
This is used to implement the float_hits behavior of get recursively.
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.
Cache
Bugs may be submitted through the RT bug tracker (or bug-Cache-Cascade@rt.cpan.org).
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
Karen Etheridge <ether@cpan.org>
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.
To install Cache::Cascade, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Cascade
CPAN shell
perl -MCPAN -e shell install Cache::Cascade
For more information on module installation, please visit the detailed CPAN module installation guide.