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
@@ -43,6 +43,15 @@
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
@@ -601,11 +601,15 @@
my ($self, $table, $params, $cols, $options) = @_;
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) {
@@ -625,10 +629,13 @@
@$cols = @$columns;
}
+ my $cache_skip = $context_options->{cache_skip};
+ $cache_skip = $options->{cache_skip} if (!defined $cache_skip);
my $tabledef = $self->{table}{$table};
my ($sds, $hashkey, @cache_colidx_map);
- 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);
@@ -658,7 +665,8 @@
$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) = @$ref;
@@ -669,9 +677,11 @@
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);
}
}
}
@@ -708,6 +718,7 @@
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) {
@@ -898,11 +909,16 @@
sub get_rows {
&App::sub_entry if ($App::trace);
my ($self, $table, $params, $cols, $options) = @_;
+
+ 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) {
@@ -922,10 +938,14 @@
@$cols = @$columns;
}
+ my $cache_skip = $context_options->{cache_skip};
+ $cache_skip = $options->{cache_skip} if (!defined $cache_skip);
+
my $tabledef = $self->{table}{$table};
my ($sds, $hashkey, @cache_colidx_map);
- 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);
@@ -953,7 +973,8 @@
$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) = @$ref;
@@ -964,9 +985,11 @@
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);
}
}
}
@@ -1009,6 +1032,7 @@
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}) {