8 use_ok "Catalyst::Plugin::Cache";
9 use_ok "Catalyst::Plugin::Cache::Choose::KeyRegexes";
11 use Catalyst::Plugin::Cache::Backend::Memory;
15 use base qw/Catalyst::Plugin::Cache Catalyst::Plugin::Cache::Choose::KeyRegexes/;
20 qr/^foo/ => "foo_store",
21 qr/^bar/ => "bar_store",
23 ### as of 0.06, you must specify a backend
25 class => 'Catalyst::Plugin::Cache::Backend::Memory',
29 sub config { \%config }
34 my $c = bless {}, "MockApp";
36 MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
37 MockApp->register_cache_backend( foo_store => Catalyst::Plugin::Cache::Backend::Memory->new );
38 MockApp->register_cache_backend( bar_store => Catalyst::Plugin::Cache::Backend::Memory->new );
40 is( $c->choose_cache_backend_wrapper( key => "baz" ), $c->default_cache_backend, "chose default" );
41 is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->get_cache_backend("foo_store"), "chose foo" );
42 is( $c->choose_cache_backend_wrapper( key => "bar" ), $c->get_cache_backend("bar_store"), "chose bar" );
44 $c->cache_set( foo_laa => "laa" );
45 $c->cache_set( bar_laa => "laa" );
46 $c->cache_set( baz_laa => "laa" );
48 is( $c->default_cache_backend->get("baz_laa"), "laa", "non match stored in default" );
49 is( $c->default_cache_backend->get("foo_laa"), undef, "no foo key" );
50 is( $c->default_cache_backend->get("bar_laa"), undef, "no bar key" );
53 is( $c->get_cache_backend("foo_store")->get("baz_laa"), undef, "no non match in foo store" );
54 is( $c->get_cache_backend("foo_store")->get("foo_laa"), "laa", "has foo key" );
55 is( $c->get_cache_backend("foo_store")->get("bar_laa"), undef, "no bar key" );
58 is( $c->get_cache_backend("bar_store")->get("baz_laa"), undef, "no non match in bar store" );
59 is( $c->get_cache_backend("bar_store")->get("foo_laa"), undef, "no foo key" );
60 is( $c->get_cache_backend("bar_store")->get("bar_laa"), "laa", "has bar key" );