6 use Test::More 'no_plan';
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",
25 sub config { \%config }
30 my $c = bless {}, "MockApp";
32 MockApp->register_cache_backend( default => Catalyst::Plugin::Cache::Backend::Memory->new );
33 MockApp->register_cache_backend( foo_store => Catalyst::Plugin::Cache::Backend::Memory->new );
34 MockApp->register_cache_backend( bar_store => Catalyst::Plugin::Cache::Backend::Memory->new );
36 is( $c->choose_cache_backend_wrapper( key => "baz" ), $c->default_cache_backend, "chose default" );
37 is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->get_cache_backend("foo_store"), "chose foo" );
38 is( $c->choose_cache_backend_wrapper( key => "bar" ), $c->get_cache_backend("bar_store"), "chose bar" );
40 $c->cache_set( foo_laa => "laa" );
41 $c->cache_set( bar_laa => "laa" );
42 $c->cache_set( baz_laa => "laa" );
44 is( $c->default_cache_backend->get("baz_laa"), "laa", "non match stored in default" );
45 is( $c->default_cache_backend->get("foo_laa"), undef, "no foo key" );
46 is( $c->default_cache_backend->get("bar_laa"), undef, "no bar key" );
49 is( $c->get_cache_backend("foo_store")->get("baz_laa"), undef, "no non match in foo store" );
50 is( $c->get_cache_backend("foo_store")->get("foo_laa"), "laa", "has foo key" );
51 is( $c->get_cache_backend("foo_store")->get("bar_laa"), undef, "no bar key" );
54 is( $c->get_cache_backend("bar_store")->get("baz_laa"), undef, "no non match in bar store" );
55 is( $c->get_cache_backend("bar_store")->get("foo_laa"), undef, "no foo key" );
56 is( $c->get_cache_backend("bar_store")->get("bar_laa"), "laa", "has bar key" );