X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FCache.pm;h=22a9354de0669529a26ce34951c9efcdf7178d5b;hb=fba82fef07d36e90f9de40804dfe4f737a052148;hp=ed606c59b80a11896909e874e58ffad01127e4f7;hpb=204b2b54f823e7a4ca8c0038a28432d78693bef8;p=catagits%2FCatalyst-Plugin-Cache.git diff --git a/lib/Catalyst/Plugin/Cache.pm b/lib/Catalyst/Plugin/Cache.pm index ed606c5..22a9354 100644 --- a/lib/Catalyst/Plugin/Cache.pm +++ b/lib/Catalyst/Plugin/Cache.pm @@ -54,8 +54,18 @@ sub setup_cache_backends { } if ( !$app->get_cache_backend("default") ) { - local $@; - eval { $app->setup_generic_cache_backend( default => $app->get_default_cache_backend_config || {} ) }; + ### XXX currently we dont have a fallback scenario + ### so die here with the error message. Once we have + ### an in memory fallback, we may consider silently + ### logging the error and falling back to that. + ### If we dont die here, the app will silently start + ### up and then explode at the first cache->get or + ### cache->set request with a FIXME error + #local $@; + #eval { + $app->setup_generic_cache_backend( default => $app->get_default_cache_backend_config || {} ); + #}; + } } @@ -81,11 +91,22 @@ sub setup_generic_cache_backend { my %config = %$config; if ( my $class = delete $config{class} ) { - eval { $app->setup_cache_backend_by_class( $name, $class, %config ) } - || - eval { $app->setup_cache_backend_by_class( $name, $class, \%config ) } - || - die "Couldn't construct $class with either list style or hash ref style param passing: $@"; + + ### try as list and as hashref, collect the + ### error if things go wrong + ### if all goes well, exit the loop + my @errors; + for my $aref ( [%config], [\%config] ) { + eval { $app->setup_cache_backend_by_class( + $name, $class, @$aref + ); + } ? do { @errors = (); last } + : push @errors, "\t$@"; + } + + ### and die with the errors if we have any + die "Couldn't construct $class with either list style or hash ref style param passing:\n @errors" if @errors; + } elsif ( my $store = delete $config->{store} || $app->default_cache_store ) { my $method = lc("setup_${store}_cache_backend"); @@ -279,9 +300,17 @@ Catalyst::Plugin::Cache - Flexible caching support for Catalyst. # configure a backend or use a store plugin __PACKAGE__->config->{cache}{backend} = { class => "Cache::Bounded", - # ... params ... + # ... params for Cache::Bounded... }; + # typical example for Cache::Memcached::libmemcached + __PACKAGE__->config->{cache}{backend} = { + class => "Cache::Memcached::libmemcached", + servers => ['127.0.0.1:11211'], + debug => 2, + }; + + # In a controller: sub foo : Local {