The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mason::Plugin::Cache - Provide component cache object and filter

VERSION

version 0.01

SYNOPSIS

    my $result = $.cache->get('key');
    if (!defined($result)) {
        ... compute $result ...
        $.cache->set('key', $result, '5 minutes');
    }

    ...

    <% $.Cache('key2', '1 hour') { %>
      <!-- this will be cached for an hour -->
    </%>

DESCRIPTION

Adds a cache method and Cache filter to access a cache (CHI) object with a namespace unique to the component.

INTERP PARAMETERS

cache_defaults

Hash of parameters passed to cache constructor. Defaults to

    driver=>'File', root_dir => 'DATA_DIR/cache'

which will create a basic file cache under Mason's data directory.

cache_root_class

Class used to create a cache. Defaults to CHI.

COMPONENT METHODS

cache

Returns a new cache object with the namespace set to the component's path. Parameters to this method, if any, are combined with cache_defaults and passed to the cache_root_class constructor. The cache object is memoized when no parameters are passed.

FILTERS

Cache ($key, $set_options, [%cache_params])

Caches the content using $self->cache and the supplied cache $key. $set_options, if provided, is passed as the third argument to $self->cache->set - it is usually an expiration time. %cache_params, if any, are passed to $self->cache.

    <% $.Cache($my_key, '1 hour') { %>
      <!-- this will be cached for an hour -->
    </%>

AUTHOR

Jonathan Swartz <swartz@pobox.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Jonathan Swartz.

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