NAME

Beekeeper::Worker::Util::SharedCache - Locally mirrored shared cache

VERSION

Version 0.03

SYNOPSIS

use Beekeeper::Worker::Util 'shared_cache'

my $c = $self->shared_cache(
    id      => "mycache",
    max_age => 300,
    persist => 1,
);

$c->set( $key => $value );
$c->get( $key );
$c->delete( $key );
$c->touch( $key );

DESCRIPTION

This module implements a locally mirrored shared cache: each worker keeps a copy of all cached data, and all copies are synced through message bus.

Access operations are essentially free, as data is held locally. But changes are expensive as they need to be propagated to every worker, and memory usage is high due to data cloning.

Keep in mind that retrieved data may be stale due to latency in changes propagation through the bus (which involves two network operations).

Even if you are using this cache for small data sets that do not change very often, please consider if a distributed memory cache like Redis or such (or even a plain DB) is a better alternative.

AUTHOR

José Micó, jose.mico@gmail.com

COPYRIGHT AND LICENSE

Copyright 2015-2021 José Micó.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language itself.

This software is distributed in the hope that it will be useful, but it is provided “as is” and without any express or implied warranties. For details, see the full text of the license in the file LICENSE.