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.
This method will delegate
get to every cache object in order, and return the first match.
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.
set_deep is set to a true value this method will delegate
set to every cache object in the list.
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.
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
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.