[Catalyst-commits] r7812 - in trunk/Catalyst-Plugin-Cache: . lib/Catalyst/Plugin

kane at dev.catalyst.perl.org kane at dev.catalyst.perl.org
Tue May 27 09:49:27 BST 2008


Author: kane
Date: 2008-05-27 09:49:26 +0100 (Tue, 27 May 2008)
New Revision: 7812

Modified:
   trunk/Catalyst-Plugin-Cache/
   trunk/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm
Log:
 r5389 at coke:  josboum | 2008-05-26 18:32:47 +0200
 * clarify the documentation on how to configure a cache implementation
   use the popular cache::memcached::libmemcached as an example
 * the old code was throwing away the first error when creating a cache instance
   (it did so using a list and a hashref as args); if the first failed, the 2nd
   call would overwrite the first error. This is now fixed
 * the calling code wrapped the above code in an eval, and then silently discarded
   the return value. This is now no longer the case, as the assumption of the code
   was to have a working fallback, which is not currently implemented. This resulted
   in a FIXME error on the first request to a controller using a cache->get or cache->set



Property changes on: trunk/Catalyst-Plugin-Cache
___________________________________________________________________
Name: svk:merge
   + 391f84f8-cfa2-4f6b-a47d-f52c5dc88d86:/local/catalyst-plugin-cache:5389

Modified: trunk/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm
===================================================================
--- trunk/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm	2008-05-27 02:42:11 UTC (rev 7811)
+++ trunk/Catalyst-Plugin-Cache/lib/Catalyst/Plugin/Cache.pm	2008-05-27 08:49:26 UTC (rev 7812)
@@ -54,8 +54,18 @@
     }
 
     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 @@
     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 @@
     # 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 {




More information about the Catalyst-commits mailing list