[MKDoc-commit] [Petal] Fix that adds language to the mix when generating cache keys

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Wed Mar 16 11:26:22 GMT 2005


Log Message:
-----------
[Petal] Fix that adds language to the mix when generating cache keys

Modified Files:
--------------
    Petal:
        Changes
    Petal/lib:
        Petal.pm
    Petal/lib/Petal/Cache:
        Disk.pm
        Memory.pm
    Petal/t:
        085_lang_include_memcache.t
        086_lang_include_diskcache.t

-------------- next part --------------
Index: Changes
===================================================================
RCS file: /var/spool/cvs/Petal/Changes,v
retrieving revision 1.129
retrieving revision 1.130
diff -LChanges -LChanges -u -r1.129 -r1.130
--- Changes
+++ Changes
@@ -6,6 +6,7 @@
     - Skip test 071 when URI.pm not installed (William McKee)
     - Added tests 085 & 086 demonstrating breakage when using {disk,mem} cache and multi-language includes
     - $Petal::Hash::String::VARIABLE_RE_BRACKETS no longer treats ${1} as a variable
+    - Fix that adds language to the mix when generating cache keys
 
 2.15 Wed Jan  5 15:31:00 2005
     - Fixed some 'used of uninitialized values' warnings
Index: Petal.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal.pm,v
retrieving revision 1.126
retrieving revision 1.127
diff -Llib/Petal.pm -Llib/Petal.pm -u -r1.126 -r1.127
--- lib/Petal.pm
+++ lib/Petal.pm
@@ -606,7 +606,7 @@
 sub _code_disk_cached
 {
     my $self = shift;
-    my $code = (defined $DISK_CACHE and $DISK_CACHE) ? Petal::Cache::Disk->get ($self->_file_path_with_macro) : undef;
+    my $code = (defined $DISK_CACHE and $DISK_CACHE) ? Petal::Cache::Disk->get ($self->_file_path_with_macro, $self->language) : undef;
     unless (defined $code)
     {
 	my $macro = $self->_macro() || $MT_NAME_CUR;
@@ -617,7 +617,7 @@
 	my $data_ref = $self->_canonicalize;
 	load_code_generator();
 	$code = $CodeGenerator->process ($data_ref, $self);
-	Petal::Cache::Disk->set ($self->_file_path_with_macro, $code) if (defined $DISK_CACHE and $DISK_CACHE);
+	Petal::Cache::Disk->set ($self->_file_path_with_macro, $code, $self->language) if (defined $DISK_CACHE and $DISK_CACHE);
     }
     
     return $code;
@@ -630,7 +630,7 @@
 sub _code_memory_cached
 {
     my $self = shift;
-    my $code = (defined $MEMORY_CACHE and $MEMORY_CACHE) ? Petal::Cache::Memory->get ($self->_file_path_with_macro) : undef;
+    my $code = (defined $MEMORY_CACHE and $MEMORY_CACHE) ? Petal::Cache::Memory->get ($self->_file_path_with_macro, $self->language) : undef;
     unless (defined $code)
     {
 	my $code_perl = $self->_code_disk_cached;
@@ -656,7 +656,7 @@
 	    $code = $VAR1;
 	}
 	
-	Petal::Cache::Memory->set ($self->_file_path_with_macro, $code) if (defined $MEMORY_CACHE and $MEMORY_CACHE);	
+	Petal::Cache::Memory->set ($self->_file_path_with_macro, $code, $self->language) if (defined $MEMORY_CACHE and $MEMORY_CACHE);	
     }
     
     return $code;
Index: Memory.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cache/Memory.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -Llib/Petal/Cache/Memory.pm -Llib/Petal/Cache/Memory.pm -u -r1.6 -r1.7
--- lib/Petal/Cache/Memory.pm
+++ lib/Petal/Cache/Memory.pm
@@ -30,8 +30,9 @@
 {
     my $class = shift;
     my $file  = shift;
-    my $key = $class->compute_key ($file);
     my $data  = shift;
+    my $lang  = shift || '';
+    my $key = $class->compute_key ($file, $lang);
     return $FILE_TO_SUBS->{$key} if ($class->is_ok ($file));
     return;
 }
@@ -44,8 +45,9 @@
 {
     my $class = shift;
     my $file  = shift;
-    my $key = $class->compute_key ($file);
     my $code  = shift;
+    my $lang  = shift || '';
+    my $key = $class->compute_key ($file, $lang);
     $FILE_TO_SUBS->{$key} = $code;
     $FILE_TO_MTIME->{$key} = $class->current_mtime ($file);
 }
@@ -58,7 +60,8 @@
 {
     my $class = shift;
     my $file  = shift;
-    my $key = $class->compute_key ($file);
+    my $lang  = shift || '';
+    my $key = $class->compute_key ($file, $lang);
     return unless (defined $FILE_TO_SUBS->{$key});
     
     my $cached_mtime = $class->cached_mtime ($file);
@@ -75,7 +78,8 @@
 {
     my $class = shift;
     my $file = shift;
-    my $key = $class->compute_key ($file);
+    my $lang = shift || '';
+    my $key = $class->compute_key ($file, $lang);
     return $FILE_TO_MTIME->{$key};
 }
 
@@ -102,8 +106,9 @@
 {
     my $class = shift;
     my $file = shift;
+    my $lang = shift || '';
     
-    my $key = $file . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT;
+    my $key = $file . ";$lang" . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT;
     return $key;
 }
 
Index: Disk.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cache/Disk.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -Llib/Petal/Cache/Disk.pm -Llib/Petal/Cache/Disk.pm -u -r1.16 -r1.17
--- lib/Petal/Cache/Disk.pm
+++ lib/Petal/Cache/Disk.pm
@@ -40,7 +40,8 @@
 {
     my $class = shift;
     my $file  = shift;
-    my $key   = $class->compute_key ($file);
+    my $lang  = shift || '';
+    my $key   = $class->compute_key ($file, $lang);
     return $class->cached ($key) if ($class->is_ok ($file));
     return;
 }
@@ -54,7 +55,8 @@
     my $class = shift;
     my $file  = shift;
     my $data  = shift;
-    my $key   = $class->compute_key ($file);
+    my $lang  = shift || '';
+    my $key   = $class->compute_key ($file, $lang);
     my $tmp   = $class->tmp;
     {
 	if ($] > 5.007)
@@ -79,8 +81,9 @@
 {
     my $class = shift;
     my $file  = shift;
+    my $lang  = shift || '';
     
-    my $key = $class->compute_key ($file);
+    my $key = $class->compute_key ($file, $lang);
     my $tmp = $class->tmp;    
     my $tmp_file = "$tmp/$key";
     return unless (-e $tmp_file);
@@ -100,8 +103,9 @@
 {
     my $class = shift;
     my $file = shift;
+    my $lang = shift || '';
     
-    my $key = md5_hex ($file . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT);
+    my $key = md5_hex ($file . ";$lang" . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT);
     $key = $PREFIX . "_" . $Petal::VERSION . "_" . $key if (defined $PREFIX);
     return $key;
 }
@@ -115,7 +119,8 @@
 {
     my $class = shift;
     my $file = shift;
-    my $key = $class->compute_key ($file);
+    my $lang = shift || '';
+    my $key = $class->compute_key ($file, $lang);
     my $tmp = $class->tmp;
     
     my $tmp_file = "$tmp/$key";
Index: 086_lang_include_diskcache.t
===================================================================
RCS file: /var/spool/cvs/Petal/t/086_lang_include_diskcache.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lt/086_lang_include_diskcache.t -Lt/086_lang_include_diskcache.t -u -r1.1 -r1.2
--- t/086_lang_include_diskcache.t
+++ t/086_lang_include_diskcache.t
@@ -55,11 +55,8 @@
 $output = eval { $template->process(@args) };
 
 ok(!$@, "template with lang and includes successfully processed");
-TODO: {
-   local $TODO = 'Memory cache breakage';
 like($output, qr{^\s*
   <p>\s+
   <span>Bonjour,\sMonde\s\(fr-CA\)</span>\s+
   </p>
 }x, "output is correct");
-};
Index: 085_lang_include_memcache.t
===================================================================
RCS file: /var/spool/cvs/Petal/t/085_lang_include_memcache.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lt/085_lang_include_memcache.t -Lt/085_lang_include_memcache.t -u -r1.1 -r1.2
--- t/085_lang_include_memcache.t
+++ t/085_lang_include_memcache.t
@@ -55,11 +55,8 @@
 $output = eval { $template->process(@args) };
 
 ok(!$@, "template with lang and includes successfully processed");
-TODO: {
-   local $TODO = 'Memory cache breakage';
 like($output, qr{^\s*
   <p>\s+
   <span>Bonjour,\sMonde\s\(fr-CA\)</span>\s+
   </p>
 }x, "output is correct");
-};


More information about the MKDoc-commit mailing list