Author: spadkins
Date: Fri May 21 09:56:51 2010
New Revision: 14000

Modified:
   p5ee/trunk/App-Repository/lib/App/Repository.pm
   p5ee/trunk/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm

Log:
add support for cache_exception_on_miss

Modified: p5ee/trunk/App-Repository/lib/App/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository.pm     (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository.pm     Fri May 21 09:56:51 2010
@@ -628,6 +628,11 @@
         if ($tabledef->{cache_name} && !$cache_skip) {
             my $cache_refresh = $context_options->{cache_refresh};
             $cache_refresh = $options->{cache_refresh} if (!defined 
$cache_refresh);
+            my $cache_exception_on_miss = $options->{cache_exception_on_miss};
+            if ($cache_exception_on_miss) {
+                $options = { %$options };
+                delete $options->{cache_exception_on_miss};
+            }
             my $cache_minimum_columns = $tabledef->{cache_minimum_columns};
             if ($cache_minimum_columns) {
                 my (%colidx, $col);
@@ -671,9 +676,14 @@
                     }
                     $context->log("Cache Hit:   $table $hashkey (get_row)\n") 
if ($log_cache);
                 }
-                else {
-                    $row = undef;
-                    $context->log("Cache Miss:  $table $hashkey (get_row)\n") 
if ($log_cache);
+                else {  # missed the cache (no cache entry exists)
+                    if ($cache_exception_on_miss) {
+                        die "CACHE-MISS:get_row($table)";
+                    }
+                    else {
+                        $row = undef;
+                        $context->log("Cache Miss:  $table $hashkey 
(get_row)\n") if ($log_cache);
+                    }
                 }
             }
         }
@@ -939,6 +949,11 @@
         if ($tabledef->{cache_name} && !$cache_skip) {
             my $cache_refresh = $context_options->{cache_refresh};
             $cache_refresh = $options->{cache_refresh} if (!defined 
$cache_refresh);
+            my $cache_exception_on_miss = $options->{cache_exception_on_miss};
+            if ($cache_exception_on_miss) {
+                $options = { %$options };
+                delete $options->{cache_exception_on_miss};
+            }
             my $cache_minimum_columns = $tabledef->{cache_minimum_columns};
             if ($cache_minimum_columns) {
                 my (%colidx, $col);
@@ -980,9 +995,14 @@
                     }
                     $context->log("Cache Hit:   $table $hashkey (get_rows)\n") 
if ($log_cache);
                 }
-                else {
-                    $rows = undef;
-                    $context->log("Cache Miss:  $table $hashkey (get_rows)\n") 
if ($log_cache);
+                else {  # missed the cache (no cache entry exists)
+                    if ($cache_exception_on_miss) {
+                        die "CACHE-MISS:get_rows($table)";
+                    }
+                    else {
+                        $rows = undef;
+                        $context->log("Cache Miss:  $table $hashkey 
(get_rows)\n") if ($log_cache);
+                    }
                 }
             }
         }

Modified: p5ee/trunk/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm      
(original)
+++ p5ee/trunk/App-Repository/lib/App/SessionObject/RepositoryObjectSet.pm      
Fri May 21 09:56:51 2010
@@ -221,7 +221,7 @@
 
 sub _get_all_objects {
     &App::sub_entry if ($App::trace);
-    my ($self) = @_;
+    my ($self, $options) = @_;
     my $objects = $self->{objects};
     if (!$objects) {
         if ($self->{temporary}) {
@@ -237,7 +237,13 @@
             # Make a copy of $params so that if $db->get_objects() changes 
them,
             # it does not affect the cacheing aspects of the object set.
             $params = {%$params};
-            $objects = $rep->get_objects($table, $params, $columns, 
{extend_columns => 1});
+            if ($options) {
+                $options = { %$options, extend_columns => 1 };
+            }
+            else {
+                $options = { extend_columns => 1 };
+            }
+            $objects = $rep->get_objects($table, $params, $columns, $options);
             $self->{objects}      = $objects;
             $self->{max_age_time} = time();
         }
@@ -544,13 +550,16 @@
     $self->_clear_cache_if_auto_params_changed($options) if (defined 
$self->{auto_params});
     $self->_clear_cache_if_objects_expired($options) if ((defined 
$options->{max_age} || defined $self->{max_age}) && $self->{objects});
 
-    my ($objects);
+    my ($objects, $get_options);
     if ($key) {
         my $index = $self->get_index($key_name, $key_columns);
         $objects = $index->{$key} || [];
     }
     else {
-        $objects = $self->_get_all_objects();
+        if ($options->{cache_exception_on_miss}) {
+            $get_options = { cache_exception_on_miss => 1 };
+        }
+        $objects = $self->_get_all_objects($get_options);
     }
     &App::sub_exit($objects) if ($App::trace);
     return($objects);

Reply via email to