Nic Sandfield > Mojar-1.062 > Mojar::Cache

Download:
Mojar-1.062.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source   Latest Release: Mojar-2.023

NAME ^

Mojar::Cache - Bare-bones in-memory cache

SYNOPSIS ^

  use Mojar::Cache;

  my $cache = Mojar::Cache->new;
  $cache->set(foo => 'bar');
  my $foo = $cache->get('foo');

DESCRIPTION ^

A minimalist cache intended to be easily upgradeable to CHI.

ATTRIBUTES ^

Mojar::Cache implements the following attributes.

namespace

  $cache->namespace('Admin');
  $namespace = $cache->namespace;

Namespace for the cache, defaults to main.

#=head2 on_get_error # # my $cb = $cache->on_get_error; # $cache = $cache->on_get_error(sub { ... }); # #Callback triggered by get exception, defaults to a null sub. # #=head2 on_set_error # # my $cb = $cache->on_set_error; # $cache = $cache->on_set_error(sub { ... }); # #Callback triggered by set exception, defaults to a null sub.

METHODS ^

get

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

Get cached value.

set

  $cache = $cache->set(foo => 'bar');

Set cache value.

RATIONALE ^

Mojo::Cache is beautifully simple but sometimes too barebones; CHI is the proper way to do serious cacheing but cannot be done on a small footprint. I wanted minor extensions to the former with an upgrade path to the latter.

SEE ALSO ^

Mojo::Cache, CHI.

syntax highlighting: