Added Cache::FileCache support.

This commit is contained in:
JT Smith 2002-12-17 08:08:30 +00:00
parent 0938e9d6cb
commit 77a5b7406a
2 changed files with 12 additions and 39 deletions

View file

@ -15,9 +15,9 @@ package WebGUI::International;
=cut
#Test to see if IPC::Shareable will load.
my $hasIPC=1;
eval " use IPC::Shareable; "; $hasIPC=0 if $@;
#Test to see if Cache::FileCache will load.
my $hasCache=1;
eval " use Cache::FileCache; "; $hasCache=0 if $@;
use strict;
use WebGUI::Session;
@ -69,18 +69,8 @@ An integer that specifies the language that the user should see. Defaults to th
=cut
sub get {
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.");
}
my ($output, $language, $namespace, $cache);
my $useCache = ($hasCache && $session{config}{cacheInternational});
if ($_[2] ne "") {
$language = $_[2];
} elsif ($session{user}{language} ne "") {
@ -93,15 +83,17 @@ sub get {
} else {
$namespace = "WebGUI";
}
if ($useCache && $international{$language}{$namespace}{$_[0]}) {
$output = $international{$language}{$namespace}{$_[0]};
} else {
if ($useCache) {
$cache = new Cache::FileCache({'namespace'=>'International'});
$output = $cache->get($language."_".$namespace."_".$_[0]);
}
if (not defined $output) {
($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);
$cache->set($language."_".$namespace."_".$_[0], $output) if ($useCache);
}
return $output;
}