| Catalyst-Plugin-Cache documentation | Contained in the Catalyst-Plugin-Cache distribution. |
Catalyst::Plugin::Cache::Curried - Curried versions of cache_set,
cache_get and cache_remove that look more like a backend.
my $curried = $c->cache( %meta );
$curried->get( $key, $value ); # no need to specify %meta
See META DATA in Catalyst::Plugin::Cache for details.
Create a new curried cache, that captures %meta.
This calls choose_cache_backend on the $c object with the captured meta and
the additional meta.
Dellegate to the c object's cache_set, cache_get, cache_remove
or cache_compute with the arguments, then the captured meta from meta,
and then the additional meta.
Returns the array ref that captured %meta from new.
The captured $c object to delegate to.
| Catalyst-Plugin-Cache documentation | Contained in the Catalyst-Plugin-Cache distribution. |
#!/usr/bin/perl package Catalyst::Plugin::Cache::Curried; use strict; use warnings; use base qw/Class::Accessor::Fast/; use Scalar::Util (); __PACKAGE__->mk_accessors(qw/c meta/); sub new { my ( $class, $c, @meta ) = @_; my $self = $class->SUPER::new({ c => $c, meta => \@meta, }); Scalar::Util::weaken( $self->{c} ) if ref( $self->{c} ); return $self; } sub backend { my ( $self, @meta ) = @_; $self->c->choose_cache_backend( @{ $self->meta }, @meta ) } sub set { my ( $self, $key, $value, @meta ) = @_; @meta = ( expires => $meta[0] ) if @meta == 1; $self->c->cache_set( $key, $value, @{ $self->meta }, @meta ); } sub get { my ( $self, $key ) = @_; $self->c->cache_get( $key, @{ $self->meta } ); } sub remove { my ( $self, $key ) = @_; $self->c->cache_remove( $key, @{ $self->meta } ); } sub compute { my ($self, $key, $code, @meta) = @_; @meta = ( expires => $meta[0] ) if @meta == 1; $self->c->cache_compute( $key, $code, @{ $self->meta }, @meta ); } __PACKAGE__; __END__