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

NAME

CGI::Application::Plugin::Cache::Adaptive - Provide cacheable to method using attribute.

VERSION

version 0.03

SYNOPSIS

  package MyApp;
  use base qw(CGI::Application);
  use CGI::Application::Plugin::Cache::Adaptive;
  
  use Cache::FileCache;
  
  sub setup {
    my $self = shift;

    $self->start_mode('default');
    $self->run_modes(
        'default' => 'do_default'
    );
  
    $self->cache_adaptive({
        backend => Cache::FileCache->new({
            namespace => 'html_cache',
            max_size  => 10 * 1024 * 1024,
        }),
        expires_min => 3,
        expires_max => 60,
        check_load  => sub {
            my $entry = shift;
            int($entry->{process_time} * 2) - 1;
        },
    });
  }
  
  sub do_default : Cacheable(qw/path path_info query/) {
    sleep 10;
    return "test";
  }

DESCRIPTION

This module provides adaptive cache to specified method by 'Cacheable' attribute. Cache mechanism depends on Cache::Adaptive.

USAGE

Cacheable attribute

Cacheable attribute is able to accept some arguments. The arguments effects Cache::Adaptive behavior.

The arguments must be array or hash reference. See below the arguments detail.

Array arguments

Example,

    sub do_something : Cacheable(qw/path session/) {
        # process by user
    }

Array arguments accepts 4 items,

path

Add path(script_name) to cache key salt.

query

Add query string to cache key salt.

path_info

Add path_info to cache key salt.

session

Add session_id to cache key salt.

Hash reference arguments

Example,

    sub do_something : Cacheable({key_from => [qw/path path_info/], label => 'memcached'}) {
        # some process
    }

Hash reference accepts 2 original key and any key permitted by Cache::Adaptive's access method.

key_from

Same as array arguments. See "Array arguments" in CGI::Application::Plugin::Cache::Adaptive.

label

Change cache profile to specified labeled cache object. See "cache_adaptive($label)" in Cache::Adaptive.

METHODS

cache_adaptive()

Alias cache_adaptive('default'). See "cache_adaptive($label)" in CGI::Application::Plugin::Cache::Adaptive

cache_adaptive($label)

Get Cache::Adaptive object by label.

cache_adaptive($hash_ref)

Set Cache::Adaptive object to 'default' label. The $hash_ref is Cache::Adaptive's new parameter.

cache_adaptive($cache_obj)

Set Cache::Adaptive or that inheritance object to 'default' label.

cache_adaptive($label, $hash_ref)

Set Cache::Adaptive object to specified label. The $hash_ref is Cache::Adaptive's new parameter.

cache_adaptive($label, $cache_obj)

Set Cache::Adaptive or that inheritance object to specified label.

CGI::Application::Cacheable()

Provide cacheable to specified method. See Attribute::Handlers

SEE ALSO

Cache::Adaptive
CGI::Application
CGI::Application::Plugin::AutoRunmode
Attribute::Handlers

AUTHOR

Toru Yamaguchi, <zigorou@cpan.org>

THANKS

Kazuho Oku, <kazuhooku@gmail.com>

BUGS

Please report any bugs or feature requests to bug-cgi-application-plugin-cache-adaptive@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Copyright 2007 Toru Yamaguchi, All Rights Reserved.

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