NAME
Starch::Store::Layered - Layer multiple Starch stores.
SYNOPSIS
my $starch = Starch->new(
expires => 2 * 60 * 60, # 2 hours
store => {
class => '::Layered',
outer => {
class=>'::CHI',
max_expires => 10 * 60, # 10 minutes
...,
},
inner => {
class=>'::MongoDB',
...,
},
},
);
DESCRIPTION
This store provides the ability to declare two stores that act in a layered fashion where all writes (set
and remove
) are applied to both stores but all reads (get
) are attempted, first, on the "outer" store, and if that fails the read is attempted in the "inner" store.
When get
is called, if the outer store did not have the data, but the inner store did, then the data will be automatically written to the outer store.
The most common use-case for this store is for placing a cache in front of a persistent store. Typically caches are much faster than persistent storage engines.
Another use case is for migrating from one store to another. Your new store would be set as the inner store, and your old store would be set as the outer store. Once sufficient time has passed, and the new store has been populated, you could switch to using just the new store.
If you'd like to layer more than two stores you can use layered stores within layered stores.
REQUIRED ARGUMENTS
outer
This is the outer store, the one that tries to handle read requests first before falling back to the "inner" store.
Accepts the same value as "store" in Starch::Manager.
inner
This is the inner store, the one that only handles read requests if the "outer" store was unable to.
Accepts the same value as "store" in Starch::Manager.
ATTRIBUTES
can_reap_expired
Return true if either the "inner" or "outer" stores support the "reap_expired" in Starch::Store method.
METHODS
reap_expired
Calls "reap_expired" in Starch::Store on the "outer" and "inner" stores, if they support expired state reaping.
set
get
remove
Set "remove" in Starch::Store.
SUPPORT
See "SUPPORT" in Starch.
AUTHORS
See "AUTHORS" in Starch.
LICENSE
See "LICENSE" in Starch.