Added international caching mechanism.
This commit is contained in:
parent
fec0a6e21d
commit
d241598851
2 changed files with 39 additions and 5 deletions
|
|
@ -14,12 +14,15 @@ package WebGUI::International;
|
|||
|
||||
=cut
|
||||
|
||||
|
||||
#Test to see if IPC::Shareable will load.
|
||||
my $hasIPC=1;
|
||||
eval " use IPC::Shareable; "; $hasIPC=0 if $@;
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
my %international;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::International
|
||||
|
|
@ -66,7 +69,18 @@ An integer that specifies the language that the user should see. Defaults to th
|
|||
=cut
|
||||
|
||||
sub get {
|
||||
my ($output, $language, $namespace);
|
||||
my ($output, $language, $namespace, %international);
|
||||
my $useCache = ($session{env}{MOD_PERL} && $hasIPC && $session{config}{cacheInternational});
|
||||
if ($useCache) {
|
||||
my $glue = 'intl';
|
||||
my %options = (
|
||||
create => 0,
|
||||
exclusive => 0,
|
||||
mode => 0666,
|
||||
destroy => 0,
|
||||
);
|
||||
tie %international, 'IPC::Shareable', $glue, { %options } or WebGUI::ErrorHandler::warn("Couldn't cache international message.");
|
||||
}
|
||||
if ($_[2] ne "") {
|
||||
$language = $_[2];
|
||||
} elsif ($session{user}{language} ne "") {
|
||||
|
|
@ -79,14 +93,15 @@ sub get {
|
|||
} else {
|
||||
$namespace = "WebGUI";
|
||||
}
|
||||
if (defined $international{$language}{$_[0]}) { # a little caching never hurts =)
|
||||
$output = $international{$language}{$_[0]};
|
||||
if ($useCache && $international{$language}{$namespace}{$_[0]}) {
|
||||
$output = $international{$language}{$namespace}{$_[0]};
|
||||
} else {
|
||||
($output) = WebGUI::SQL->quickArray("select message from international
|
||||
where internationalId=$_[0] and namespace='$namespace' and languageId='$language'");
|
||||
if ($output eq "" && $language ne 1) {
|
||||
$output = get($_[0],$namespace,1);
|
||||
}
|
||||
$international{$language}{$namespace}{$_[0]} = $output if ($useCache);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,25 @@ use POSIX ();
|
|||
|
||||
|
||||
|
||||
#----------------------------------------
|
||||
# International Message Caching
|
||||
#----------------------------------------
|
||||
#Test to see if IPC::Sharable will load.
|
||||
my $hasIPC=1;
|
||||
eval " use IPC::Shareable (); "; $hasIPC=0 if $@;
|
||||
my (%international);
|
||||
if ($hasIPC) {
|
||||
my $glue = 'intl';
|
||||
my %options = (
|
||||
create => 'yes',
|
||||
exclusive => 0,
|
||||
mode => 0666,
|
||||
destroy => 'yes',
|
||||
);
|
||||
tie %international, 'IPC::Shareable', $glue, { %options };
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------
|
||||
# Database connectivity.
|
||||
#----------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue