Catalyst::Plugin::Cache draft
[catagits/Catalyst-Plugin-Cache.git] / lib / Catalyst / Plugin / Cache / Choose / KeyRegexes.pm
CommitLineData
c28ee69c 1#!/usr/bin/perl
2
3package Catalyst::Plugin::Cache::Choose::KeyRegexes;
4
5use strict;
6use warnings;
7
8sub setup {
9 my $app = shift;
10 my $ret = $app->NEXT::setup( @_ );
11
12 my $regexes = $app->config->{cache}{key_regexes} ||= [];
13
14 die "the regex list must be an array containing regexex/backend pairs" unless ref $regexes eq "ARRAY";
15
16 $ret;
17}
18
19sub get_cache_key_regexes {
20 my ( $c, %meta ) = @_;
21 @{ $c->config->{cache}{key_regexes} };
22}
23
24sub choose_cache_backend {
25 my ( $c, %meta ) = @_;
26
27 my @regexes = $c->get_cache_key_regexes( %meta );
28
29 while ( @regexes and my ( $re, $backend ) = splice( @regexes, 0, 2 ) ) {
30 return $backend if $meta{key} =~ $re;
31 }
32
33 $c->NEXT::choose_cache_backend( %meta );
34}
35
36__PACKAGE__;
37
38__END__
39
40=pod
41
42=head1 NAME
43
44Catalyst::Plugin::Cache::Choose::KeyRegex - Choose a cache backend based on key regexes.
45
46=head1 SYNOPSIS
47
48 use Catalyst::Plugin::Cache::Choose::KeyRegex;
49
50=head1 DESCRIPTION
51
52=cut
53
54