Cache::Cascade - Get/set values to/from a group of caches, with some advanced semantics.
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 chepear 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 negligiable 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
Defaults to false. See
- get $key
This method will delegate
getto every cache object in order, and return the first match.
float_hitsis set to a true value, it will also call
setwith the match on every cache object before the one that matched.
- set $key, $value
set_deepis set to a true value this method will delegate
setto every cache object in the list.
set_deepis set to a false value this method will delegate
setjust to the first cache object in the list.
- remove $key
These methods will delegate
removeon every cache object in the list.
- entry $key
- exists $key
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.
- get_and_float_result $key, @caches
This is used to implement the
When you set or remove a key from the cascade and this propagates downards, 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.
This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/Cache-Cascade/, and use
darcs send to commit changes.
3 POD Errors
The following errors were encountered while parsing the POD:
- Around line 171:
'=item' outside of any '=over'
- Around line 185:
You forgot a '=back' before '=head1'
- Around line 236:
Expected text after =item, not a bullet