6 use Test::More 'no_plan';
8 use ok "Catalyst::Plugin::Cache";
9 use ok "Catalyst::Plugin::Cache::Choose::KeyRegexes";
13 use base qw/Catalyst::Plugin::Cache Catalyst::Plugin::Cache::Choose::KeyRegexes/;
18 qr/^foo/ => "foo_store",
19 qr/^bar/ => "bar_store",
23 sub config { \%config }
26 use Storable qw/freeze thaw/;
28 sub new { bless {}, shift }
29 sub get { ${thaw($_[0]{$_[1]}) || return} };
30 sub set { $_[0]{$_[1]} = freeze(\$_[2]) };
31 sub delete { delete $_[0]{$_[1]} };
36 my $c = bless {}, "MockApp";
38 MockApp->register_cache_backend( default => MemoryCache->new );
39 MockApp->register_cache_backend( foo_store => MemoryCache->new );
40 MockApp->register_cache_backend( bar_store => MemoryCache->new );
42 is( $c->choose_cache_backend_wrapper( key => "baz" ), $c->cache, "chose default" );
43 is( $c->choose_cache_backend_wrapper( key => "foo" ), $c->cache("foo_store"), "chose foo" );
44 is( $c->choose_cache_backend_wrapper( key => "bar" ), $c->cache("bar_store"), "chose bar" );
46 $c->cache_set( foo_laa => "laa" );
47 $c->cache_set( bar_laa => "laa" );
48 $c->cache_set( baz_laa => "laa" );
50 is( $c->cache->get("baz_laa"), "laa", "non match stored in default" );
51 is( $c->cache->get("foo_laa"), undef, "no foo key" );
52 is( $c->cache->get("bar_laa"), undef, "no bar key" );
55 is( $c->cache("foo_store")->get("baz_laa"), undef, "no non match in foo store" );
56 is( $c->cache("foo_store")->get("foo_laa"), "laa", "has foo key" );
57 is( $c->cache("foo_store")->get("bar_laa"), undef, "no bar key" );
60 is( $c->cache("bar_store")->get("baz_laa"), undef, "no non match in bar store" );
61 is( $c->cache("bar_store")->get("foo_laa"), undef, "no foo key" );
62 is( $c->cache("bar_store")->get("bar_laa"), "laa", "has bar key" );