Marquee Marquee::Cache - Cache

TABLE OF CONTENTS

NAME

Marquee::Cache - Cache

SYNOPSIS

use Marquee::Cache;

$cache = Marquee::Cache->new;
$cache->max_keys(2);
$cache->set(foo => 'bar');
$cache->get('foo');
$cache->set(baz => 'yada', sub {
    my $cached_time = shift;
    return $cached_time < (stat $file)[9];
});

DESCRIPTION

Simple cache manager with expire feature.

ATTRIBUTES

Marquee::Cache implements the following attributes.

max_keys

Max keys per instance.

$cache->max_key(200);

INSTANCE METHODS

Marquee::Cache implements the following instance methods.

get

Get cache value for given name.

my $data = $cache->get('foo');

set

Set cache values with given name and data. By 3rd argument, you can set a condition to expire the cache.

$cache->set(key, $data);
$cache->set(key, $data, sub {...});

The coderef gets the cache timestamp in seconds since the epoch and can return true for expire.

my $expire = sub { return (time() - shift > 86400) };

SEE ALSO

Marquee, Mojolicious