[Petal] [BUG] translated fragments get cached in last accessed language

Bruno Postle bruno at mkdoc.com
Fri Mar 11 14:42:04 GMT 2005


On Thu 10-Mar-2005 at 18:00 +0000, Bruno Postle wrote:

> This is a Petal bug.  Basically if I enable the Petal cache and do 
> something like this:
>
>   my $a = new Petal (file => 'foo', base_dir => 'bar', language => 'en');
>      $a = new Petal (file => 'foo', base_dir => 'bar', language => 'fr');
>
> ..Petal continues to use 'en' templates.

The problem was that Petal hard-codes paths and languages for 
included templates in the cached code - Whichever language the 
template was using when it was first-run is the language that gets 
used from then-on.

The attached patch fixes this by stirring the 'language' into the 
hash key used to store and retrieve the cached code.  I would 
appreciate it if somebody could look-over it before I commit and 
release.

-- 
Bruno
-------------- next part --------------
Index: lib/Petal.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal.pm,v
retrieving revision 1.126
diff -r1.126 Petal.pm
609c609
<     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;
620c620
< 	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);
633c633
<     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;
659c659
< 	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);	
Index: lib/Petal/Cache/Disk.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cache/Disk.pm,v
retrieving revision 1.16
diff -r1.16 Disk.pm
43c43,44
<     my $key   = $class->compute_key ($file);
---
>     my $lang  = shift || '';
>     my $key   = $class->compute_key ($file, $lang);
57c58,59
<     my $key   = $class->compute_key ($file);
---
>     my $lang  = shift || '';
>     my $key   = $class->compute_key ($file, $lang);
81a84
>     my $lang  = shift || '';
83c86
<     my $key = $class->compute_key ($file);
---
>     my $key = $class->compute_key ($file, $lang);
102a106
>     my $lang = shift || '';
104c108
<     my $key = md5_hex ($file . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT);
---
>     my $key = md5_hex ($file . ";$lang" . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT);
118c122,123
<     my $key = $class->compute_key ($file);
---
>     my $lang = shift || '';
>     my $key = $class->compute_key ($file, $lang);
Index: lib/Petal/Cache/Memory.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cache/Memory.pm,v
retrieving revision 1.6
diff -r1.6 Memory.pm
33d32
<     my $key = $class->compute_key ($file);
34a34,35
>     my $lang  = shift || '';
>     my $key = $class->compute_key ($file, $lang);
47d47
<     my $key = $class->compute_key ($file);
48a49,50
>     my $lang  = shift || '';
>     my $key = $class->compute_key ($file, $lang);
61c63,64
<     my $key = $class->compute_key ($file);
---
>     my $lang  = shift || '';
>     my $key = $class->compute_key ($file, $lang);
78c81,82
<     my $key = $class->compute_key ($file);
---
>     my $lang = shift || '';
>     my $key = $class->compute_key ($file, $lang);
104a109
>     my $lang = shift || '';
106c111
<     my $key = $file . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT;
---
>     my $key = $file . ";$lang" . ";INPUT=" . $Petal::INPUT . ";OUTPUT=" . $Petal::OUTPUT;


More information about the Petal mailing list