Skip Menu |

This queue is for tickets about the Petal CPAN distribution.

Report information
The Basics
Id: 55692
Status: resolved
Priority: 0/
Queue: Petal

People
Owner: Nobody in particular
Requestors: adam_lounds [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.19
Fixed in: (no value)



Subject: Caching broken when specifying a language
subs in Cache modules are not passing lang around, so cache keys are miscalculated. eg (Cache::Memory) sub get { my $class = shift; my $file = shift; my $data = shift; my $lang = shift || ''; my $key = $class->compute_key ($file, $lang); return $FILE_TO_SUBS->{$key} if ($class->is_ok ($file)); return; } is not using file, lang for the is_ok() call. It is also trying to use ( $class, $file, $data, $lang ) = @_, but it's called by petal as Petal::Cache::Memory->get ($self->_file_path_with_macro, $self- Show quoted text
>language)
Essentially, Petal does not cache to memory or disk if you specify a language and will re-parse the template every time.
From: adam_lounds [...] hotmail.com
Patch attached.
Subject: Petal-caching.patch
diff -rupN Petal-2.19.orig/lib/Petal/Cache/Disk.pm Petal-2.19/lib/Petal/Cache/Disk.pm --- Petal-2.19.orig/lib/Petal/Cache/Disk.pm 2005-03-11 14:08:50.000000000 +0000 +++ Petal-2.19/lib/Petal/Cache/Disk.pm 2010-05-25 09:43:41.000000000 +0100 @@ -31,7 +31,7 @@ our $TMP_DIR = File::Spec->tmpdir; our $PREFIX = 'petal_cache'; -# $class->get ($file); +# $class->get ($file, $lang); # -------------------- # Returns the cached data if its last modification time is more # recent than the last modification time of the template @@ -42,19 +42,19 @@ sub get my $file = shift; my $lang = shift || ''; my $key = $class->compute_key ($file, $lang); - return $class->cached ($key) if ($class->is_ok ($file)); + return $class->cached ($key) if ($class->is_ok ($file, $lang)); return; } -# $class->set ($file, $data); +# $class->set ($file, $code, $lang); # --------------------------- -# Sets the cached data for $file. +# Sets the cached code for $file + $lang sub set { my $class = shift; my $file = shift; - my $data = shift; + my $code = shift; my $lang = shift || ''; my $key = $class->compute_key ($file, $lang); my $tmp = $class->tmp; @@ -68,13 +68,13 @@ sub set open FP, ">$tmp/$key" or ( Carp::cluck "Cannot write-open $tmp/$key" and return ); } - print FP $data; + print FP $code; close FP; } } -# $class->is_ok ($file); +# $class->is_ok ($file, $lang); # ---------------------- # Returns TRUE if the cache is still fresh, FALSE otherwise. sub is_ok @@ -88,15 +88,15 @@ sub is_ok my $tmp_file = "$tmp/$key"; return unless (-e $tmp_file); - my $cached_mtime = $class->cached_mtime ($file); + my $cached_mtime = $class->cached_mtime ($file, $lang); my $current_mtime = $class->current_mtime ($file); return $cached_mtime >= $current_mtime; } -# $class->compute_key ($file); +# $class->compute_key ($file, $lang); # ---------------------------- -# Computes a cache 'key' for $file, which should be unique. +# Computes a cache 'key' for $file+$lang, which should be unique. # (Well, currently an MD5 checksum is used, which is not # *exactly* unique but which should be good enough) sub compute_key @@ -111,10 +111,10 @@ sub compute_key } -# $class->cached_mtime ($file); +# $class->cached_mtime ($file, $lang); # ----------------------------- # Returns the last modification date of the cached data -# for $file +# for $file + $lang sub cached_mtime { my $class = shift; diff -rupN Petal-2.19.orig/lib/Petal/Cache/Memory.pm Petal-2.19/lib/Petal/Cache/Memory.pm --- Petal-2.19.orig/lib/Petal/Cache/Memory.pm 2005-03-11 14:06:19.000000000 +0000 +++ Petal-2.19/lib/Petal/Cache/Memory.pm 2010-05-25 09:54:07.000000000 +0100 @@ -21,7 +21,7 @@ sub sillyness } -# $class->get ($file); +# $class->get ($file, $lang); # -------------------- # Returns the cached subroutine if its last modification time # is more recent than the last modification time of the template, @@ -30,15 +30,14 @@ sub get { my $class = shift; my $file = shift; - my $data = shift; my $lang = shift || ''; my $key = $class->compute_key ($file, $lang); - return $FILE_TO_SUBS->{$key} if ($class->is_ok ($file)); + return $FILE_TO_SUBS->{$key} if ($class->is_ok ($file, $lang)); return; } -# $class->set ($file, $code); +# $class->set ($file, $code, $lang); # --------------------------- # Sets the cached code for $file. sub set @@ -53,7 +52,7 @@ sub set } -# $class->is_ok ($file); +# $class->is_ok ($file, $lang); # ---------------------- # Returns TRUE if the cache is still fresh, FALSE otherwise. sub is_ok @@ -64,16 +63,16 @@ sub is_ok my $key = $class->compute_key ($file, $lang); return unless (defined $FILE_TO_SUBS->{$key}); - my $cached_mtime = $class->cached_mtime ($file); + my $cached_mtime = $class->cached_mtime ($file, $lang); my $current_mtime = $class->current_mtime ($file); return $cached_mtime >= $current_mtime; } -# $class->cached_mtime ($file); +# $class->cached_mtime ($file, $lang); # ----------------------------- # Returns the last modification date of the cached data -# for $file +# for $file & $lang sub cached_mtime { my $class = shift; diff -rupN Petal-2.19.orig/lib/Petal/CodeGenerator.pm Petal-2.19/lib/Petal/CodeGenerator.pm
Fix applied as commit 210e937ae4db87e189ab5284ee55c9ee33461b81 Released in 2.22. Many, many thanks for the patch!