Fix cache setting and cleaning up issues in the Snippet. Fixes bug #11259
This commit is contained in:
parent
50b26293c9
commit
17297f4fe6
3 changed files with 49 additions and 6 deletions
|
|
@ -4,6 +4,7 @@
|
|||
- fixed #11249: Recaptcha https bug
|
||||
- fixed #11200: Navigation in AssetProxy cached in browser
|
||||
- fixed #11143: cancel button
|
||||
- fixed #11259: Snippet content never cached
|
||||
|
||||
7.8.5
|
||||
- added the EMS submission subsystem
|
||||
|
|
|
|||
|
|
@ -176,6 +176,30 @@ sub exportGetUrlAsPath {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getCache ( $calledAsWebMethod )
|
||||
|
||||
Overrides the base method to handle Snippet specific caching.
|
||||
|
||||
=head3 $calledAsWebMethod
|
||||
|
||||
If this is true, then change the cache key.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCache {
|
||||
my $self = shift;
|
||||
my $calledAsWebMethod = shift;
|
||||
my $session = $self->session;
|
||||
my $cacheKey = "view_".$calledAsWebMethod.'_'.$self->getId;
|
||||
if ($session->env->sslRequest) {
|
||||
$cacheKey .= '_ssl';
|
||||
}
|
||||
my $cache = WebGUI::Cache->new($session, $cacheKey);
|
||||
return $cache;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getToolbar ( )
|
||||
|
||||
Returns a toolbar with a set of icons that hyperlink to functions that delete, edit, promote, demote, cut, and copy.
|
||||
|
|
@ -253,6 +277,8 @@ sub purgeCache {
|
|||
|
||||
WebGUI::Cache->new($self->session,"view__".$self->getId)->delete;
|
||||
WebGUI::Cache->new($self->session,"view_1_".$self->getId)->delete;
|
||||
WebGUI::Cache->new($self->session,"view__".$self->getId."_ssl")->delete;
|
||||
WebGUI::Cache->new($self->session,"view_1_".$self->getId."_ssl")->delete;
|
||||
$self->SUPER::purgeCache();
|
||||
}
|
||||
|
||||
|
|
@ -270,16 +296,16 @@ toolbar if in adminMode.
|
|||
=cut
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
my $calledAsWebMethod = shift;
|
||||
my $session = $self->session;
|
||||
my $session = $self->session;
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session, 1);
|
||||
my $noCache =
|
||||
$session->var->isAdminOn
|
||||
|| $self->get("cacheTimeout") <= 10
|
||||
|| ($versionTag && $versionTag->getId eq $self->get("tagId"));
|
||||
unless ($noCache) {
|
||||
my $cache = $self->getCache;
|
||||
my $cache = $self->getCache($calledAsWebMethod);
|
||||
my $out = $cache->get if defined $cache;
|
||||
return $out if $out;
|
||||
}
|
||||
|
|
@ -293,7 +319,8 @@ sub view {
|
|||
}
|
||||
WebGUI::Macro::process($session,\$output);
|
||||
unless ($noCache) {
|
||||
WebGUI::Cache->new($session,"view_".$calledAsWebMethod."_".$self->getId)->set($output,$self->get("cacheTimeout"));
|
||||
my $cache = $self->getCache($calledAsWebMethod);
|
||||
$cache->set($output,$self->get("cacheTimeout"));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ use lib "$FindBin::Bin/../lib";
|
|||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 16; # increment this value for each test you create
|
||||
use Test::More tests => 18; # increment this value for each test you create
|
||||
use WebGUI::Asset::Snippet;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Snippet Test"});
|
||||
WebGUI::Test->tagsToRollback($versionTag);
|
||||
addToCleanup($versionTag);
|
||||
my $snippet = $node->addChild({className=>'WebGUI::Asset::Snippet'});
|
||||
|
||||
# Test for a sane object type
|
||||
|
|
@ -86,6 +86,21 @@ is($snippet->view(), 'WebGUI', 'Interpolating macros in works with template in t
|
|||
my $empty = $node->addChild( { className => 'WebGUI::Asset::Snippet', } );
|
||||
is($empty->www_view, 'empty', 'www_view: snippet with no content returns "empty"');
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
#Check caching
|
||||
|
||||
##Set up the snippet to do caching
|
||||
$snippet->update({
|
||||
cacheTimeout => 100,
|
||||
snippet => 'Cache test: ^#;',
|
||||
});
|
||||
|
||||
$versionTag->commit;
|
||||
|
||||
is $snippet->view, 'Cache test: 1', 'validate snippet content and set cache';
|
||||
$session->user({userId => 3});
|
||||
is $snippet->view(1), 'Cache test: 3', 'receive uncached content since view was passed the webMethod flag';
|
||||
|
||||
TODO: {
|
||||
local $TODO = "Tests to make later";
|
||||
ok(0, 'Test indexContent method');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue