Adding caching mechanism.
This commit is contained in:
parent
c655f69a48
commit
aab64b038d
2 changed files with 28 additions and 12 deletions
|
|
@ -11,6 +11,10 @@ our $VERSION = "4.9.4";
|
|||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
#Test to see if Cache::FileCache will load.
|
||||
my $hasCache=1;
|
||||
eval " use Cache::FileCache; "; $hasCache=0 if $@;
|
||||
|
||||
use strict qw(vars subs);
|
||||
use Tie::CPHash;
|
||||
use WebGUI::ErrorHandler;
|
||||
|
|
@ -223,6 +227,14 @@ sub _processOperations {
|
|||
sub page {
|
||||
my ($debug, $positions, $wobjectOutput, $pageEdit, $httpHeader, $content, $operationOutput, $template);
|
||||
WebGUI::Session::open($_[0],$_[1]);
|
||||
my $useCache = ($hasCache && $session{config}{cachePages} && $session{form}{op} eq ""
|
||||
&& $session{form}{wid} eq "" && not $session{var}{adminOn});
|
||||
my $cache;
|
||||
my $cacheKey = "page_".$session{page}{pageId}."_".$session{user}{userId};
|
||||
if ($useCache) {
|
||||
$cache = new Cache::FileCache({'namespace'=>$_[1]});
|
||||
$content = $cache->get($cacheKey);
|
||||
}
|
||||
$operationOutput = _processOperations();
|
||||
$wobjectOutput = _processFunctions();
|
||||
if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") {
|
||||
|
|
@ -254,11 +266,15 @@ sub page {
|
|||
return $httpHeader;
|
||||
} elsif ($wobjectOutput ne "") {
|
||||
$positions->{"page.position1"} = $wobjectOutput;
|
||||
} else {
|
||||
} elsif (!($useCache && defined $content)) {
|
||||
($positions, $template, $pageEdit) = _generatePage();
|
||||
}
|
||||
$httpHeader = WebGUI::Session::httpHeader();
|
||||
$content = WebGUI::Template::process(WebGUI::Style::get($pageEdit.WebGUI::Page::getTemplate($template)), $positions);
|
||||
unless ($useCache && defined $content) {
|
||||
$content = WebGUI::Template::process(WebGUI::Style::get($pageEdit.WebGUI::Page::getTemplate($template)),
|
||||
$positions);
|
||||
$cache->set($cacheKey, $content, $session{config}{cachePages}) if ($useCache);
|
||||
}
|
||||
$debug = _generateDebug();
|
||||
WebGUI::Session::close();
|
||||
return $httpHeader.$content.$debug;
|
||||
|
|
|
|||
|
|
@ -184,23 +184,23 @@ The depth the tree should be traversed. Defaults to "0". If set to "0" the entir
|
|||
|
||||
sub tree {
|
||||
my ($sth, %data, %tree);
|
||||
tie %tree, 'Tie::IxHash';
|
||||
tie %data, 'Tie::CPHash';
|
||||
my ($parentId, $toLevel, $depth) = @_;
|
||||
$toLevel = 99 if ($toLevel > 100 || $toLevel < 1);
|
||||
if ($depth < $toLevel) {
|
||||
$sth = WebGUI::SQL->read("select urlizedTitle, menuTitle, pageId, synopsis from page
|
||||
tie %tree, 'Tie::IxHash';
|
||||
tie %data, 'Tie::CPHash';
|
||||
if ($depth < $toLevel) {
|
||||
$sth = WebGUI::SQL->read("select urlizedTitle, menuTitle, pageId, synopsis from page
|
||||
where parentId='$parentId' order by sequenceNumber");
|
||||
while (%data = $sth->hash) {
|
||||
if (WebGUI::Privilege::canViewPage($data{pageId})) {
|
||||
while (%data = $sth->hash) {
|
||||
if (WebGUI::Privilege::canViewPage($data{pageId})) {
|
||||
$tree{$data{pageId}}{url} = WebGUI::URL::gateway($data{urlizedTitle});
|
||||
$tree{$data{pageId}}{title} = $data{menuTitle};
|
||||
$tree{$data{pageId}}{synopsis} = $data{synopsis};
|
||||
$tree{$data{pageId}}{sub} = tree($data{pageId},$toLevel,($depth+1));
|
||||
}
|
||||
$tree{$data{pageId}}{sub} = tree($data{pageId},$toLevel,($depth+1));
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
return \%tree;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue