Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Cvs P5ee > [svn:p5ee] r109...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 682 of 694
Post > Topic >>

[svn:p5ee] r10935 - in p5ee/trunk/App-Repository: bin lib/App

by spadkins@[EMAIL PROTECTED] Mar 18, 2008 at 08:15 AM

Author: spadkins
Date: Tue Mar 18 08:15:49 2008
New Revision: 10935

Modified:
   p5ee/trunk/App-Repository/bin/dbget
   p5ee/trunk/App-Repository/lib/App/Repository.pm

Log:
added cache logging

Modified: p5ee/trunk/App-Repository/bin/dbget
==============================================================================
--- p5ee/trunk/App-Repository/bin/dbget	(original)
+++ p5ee/trunk/App-Repository/bin/dbget	Tue Mar 18 08:15:49 2008
@[EMAIL PROTECTED]
 -43,6 +43,15 @[EMAIL PROTECTED]
         cache_refresh => {
             description => "Skip any cached values for the table but save
the results in the cache",
         },
+        log_cache => {
+            description => "Log cache activity",
+        },
+        log_hi_res => {
+            description => "Log entries with high-resolution timestamps",
+        },
+        log_elapsed => {
+            description => "Log entries with elapsed time",
+        },
         verbose => {
             default => 1,
             description => "Verbose level",

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	Tue Mar 18 08:15:49
2008
@[EMAIL PROTECTED]
 -601,11 +601,15 @[EMAIL PROTECTED]
     my ($self, $table, $params, $cols, $options) = @[EMAIL PROTECTED]
     die "get_row(): params undefined" if (!defined $params);
 
+    my $context = $self->{context};
+    my $context_options = $context->{options};
+    my $log_cache = $context_options->{log_cache};
+
     my ($row);
     my $repname = $self->{table}{$table}{repository};
     my $realtable = $self->{table}{$table}{table} || $table;
     if (defined $repname && $repname ne $self->{name}) {
-        my $rep = $self->{context}->repository($repname);
+        my $rep = $context->repository($repname);
         $row = $rep->get_row($realtable, $params, $cols, $options);
     }
     elsif (defined $realtable && $realtable ne $table) {
@[EMAIL PROTECTED]
 -625,10 +629,13 @[EMAIL PROTECTED]
             @[EMAIL PROTECTED]
 = @[EMAIL PROTECTED]
         }
 
+        my $cache_skip = $context_options->{cache_skip};
+        $cache_skip = $options->{cache_skip} if (!defined $cache_skip);
         my $tabledef = $self->{table}{$table};
         my ($sds, $hashkey, @[EMAIL PROTECTED]
);
-        if ($tabledef->{cache_name} && !$options->{cache_skip}) {
-            my $context = $self->{context};
+        if ($tabledef->{cache_name} && !$cache_skip) {
+            my $cache_refresh = $context_options->{cache_refresh};
+            $cache_refresh = $options->{cache_refresh} if (!defined
$cache_refresh);
             my $cache_minimum_columns =
$tabledef->{cache_minimum_columns};
             if ($cache_minimum_columns) {
                 my (%colidx, $col);
@[EMAIL PROTECTED]
 -658,7 +665,8 @[EMAIL PROTECTED]
                 $hash_options = undef if (! %$hash_options);
             }
             $hashkey = $sds->hashkey([$table, $params, $cols,
$hash_options, "row"]);
-            if (!$options->{cache_refresh}) {
+            $context->log("Cache Check: $table $hashkey (get_row)\n") if
($log_cache);
+            if (!$cache_refresh) {
                 my $ref = $sds->get_ref($hashkey);
                 if (defined $ref) {
                     my ($saved_table, $saved_params, $saved_columns,
$saved_row, $saved_options) = @[EMAIL PROTECTED]
 -669,9 +677,11 @[EMAIL PROTECTED]
                     else {
                         $cols = $saved_columns
                     }
+                    $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);
                 }
             }
         }
@[EMAIL PROTECTED]
 -708,6 +718,7 @[EMAIL PROTECTED]
 
             if ($sds) {
                 $sds->set_ref($hashkey, [$table, $params, $cols, $row,
$options]);
+                $context->log("Cache Save:  $table $hashkey (get_row)\n")
if ($log_cache);
             }
         }
         if ($sds && $tabledef->{cache_minimum_columns} && $row) {
@[EMAIL PROTECTED]
 -898,11 +909,16 @[EMAIL PROTECTED]
 sub get_rows {
     &App::sub_entry if ($App::trace);
     my ($self, $table, $params, $cols, $options) = @[EMAIL PROTECTED]
    my $context = $self->{context};
+    my $context_options = $context->{options};
+    my $log_cache = $context_options->{log_cache};
+
     my ($rows);
     my $repname = $self->{table}{$table}{repository};
     my $realtable = $self->{table}{$table}{table} || $table;
     if (defined $repname && $repname ne $self->{name}) {
-        my $rep = $self->{context}->repository($repname);
+        my $rep = $context->repository($repname);
         $rows = $rep->get_rows($realtable, $params, $cols, $options);
     }
     elsif (defined $realtable && $realtable ne $table) {
@[EMAIL PROTECTED]
 -922,10 +938,14 @[EMAIL PROTECTED]
             @[EMAIL PROTECTED]
 = @[EMAIL PROTECTED]
         }
 
+        my $cache_skip = $context_options->{cache_skip};
+        $cache_skip = $options->{cache_skip} if (!defined $cache_skip);
+
         my $tabledef = $self->{table}{$table};
         my ($sds, $hashkey, @[EMAIL PROTECTED]
);
-        if ($tabledef->{cache_name} && !$options->{cache_skip}) {
-            my $context = $self->{context};
+        if ($tabledef->{cache_name} && !$cache_skip) {
+            my $cache_refresh = $context_options->{cache_refresh};
+            $cache_refresh = $options->{cache_refresh} if (!defined
$cache_refresh);
             my $cache_minimum_columns =
$tabledef->{cache_minimum_columns};
             if ($cache_minimum_columns) {
                 my (%colidx, $col);
@[EMAIL PROTECTED]
 -953,7 +973,8 @[EMAIL PROTECTED]
                 $hash_options = undef if (! %$hash_options);
             }
             $hashkey = $sds->hashkey([$table, $params, $cols,
$hash_options, "rows"]);
-            if (!$options->{cache_refresh}) {
+            $context->log("Cache Check: $table $hashkey (get_rows)\n") if
($log_cache);
+            if (!$cache_refresh) {
                 my $ref = $sds->get_ref($hashkey);
                 if (defined $ref) {
                     my ($saved_table, $saved_params, $saved_columns,
$saved_rows, $saved_options) = @[EMAIL PROTECTED]
 -964,9 +985,11 @[EMAIL PROTECTED]
                     else {
                         $cols = $saved_columns
                     }
+                    $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);
                 }
             }
         }
@[EMAIL PROTECTED]
 -1009,6 +1032,7 @[EMAIL PROTECTED]
 
             if ($sds) {
                 $sds->set_ref($hashkey, [$table, $params, $cols, $rows,
$options]);
+                $context->log("Cache Save:  $table $hashkey
(get_rows)\n") if ($log_cache);
             }
         }
         if ($sds && $tabledef->{cache_minimum_columns}) {




 1 Posts in Topic:
[svn:p5ee] r10935 - in p5ee/trunk/App-Repository: bin lib/App
spadkins@[EMAIL PROTECTED  2008-03-18 08:15:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:31:04 CDT 2008.