יובל קוג'מן (Yuval Kogman) > Cache-Cascade > Cache::Cascade

Download:
Cache-Cascade-0.05.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.05   Source  

NAME ^

Cache::Cascade - Get/set values to/from a group of caches, with some advanced semantics.

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

FIELDS
set_deep

Defaults to true. See set.

float_hits

Defaults to false. See get.

METHODS ^

get $key

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.

set $key, $value

If set_deep is set to a true value this method will delegate set to every cache object in the list.

If set_deep is set to a false value this method will delegate set just to the first cache object in the list.

remove $key
clear

These methods will delegate remove on 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_hits behavior of get recursively.

CAVEATS ^

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.

SEE ALSO ^

Cache

VERSION CONTROL ^

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.

syntax highlighting: