Nic Sandfield > Mojar-0.017 > Mojar::Cache

Download:
Mojar-0.017.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source  

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

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

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 ^

Mojar::Cache inherits all methods from Mojar::Base and implements the following new ones.

get

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

Get cached value.

set

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

Set cached 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: