Skip to content

Commit

Permalink
Item14012: prevent page caching under certain conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Mar 8, 2016
1 parent 8a048da commit 7535172
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions core/lib/Foswiki/PageCache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ sub cachePage {
my $variationKey = $this->genVariationKey();

# remove old entries
if ( $refresh =~ m/^(on|cache|all)$/ ) {
if ( $session->inContext("isadmin") && $refresh =~ m/^(on|cache|all)$/ ) {
$this->deletePage( $web, $topic ); # removes all variations
}
else {
Expand Down Expand Up @@ -335,7 +335,6 @@ sub getPage {
if ( $refresh eq 'fire' ) { # simulates a "save" of the current topic
$this->fireDependency( $web, $topic );
}
return undef if $refresh =~ m/^(on|cache|all|fire)$/;

# check cacheability
return undef unless $this->isCacheable( $web, $topic );
Expand Down Expand Up @@ -404,25 +403,29 @@ sub isCacheable {
$isCacheable = 1;

my $session = $Foswiki::Plugins::SESSION;
$isCacheable = 0 if $session->inContext('command_line');

# check for errors parsing the url path
$isCacheable = 0 if $session->{invalidWeb} || $session->{invalidTopic};

# POSTs and HEADs aren't cacheable
my $method = $session->{request}->method;
$isCacheable = 0 if $method && $method =~ m/^(?:POST|HEAD)$/;

if ($isCacheable) {
my $method = $session->{request}->method;
$isCacheable = 0 if $method && $method =~ m/^(?:POST|HEAD)$/;
}

# check prefs value
# check prefs value
if ($isCacheable) {
my $flag = $session->{prefs}->getPreference('CACHEABLE');
$isCacheable = 0 if defined $flag && !Foswiki::isTrue($flag);
}

# don't cache 401 Not authorized responses
my $headers = $session->{response}->headers();
my $status = $headers->{Status};
$isCacheable = 0 if $status && $status eq 401;
if ($isCacheable) {
my $headers = $session->{response}->headers();
my $status = $headers->{Status};
$isCacheable = 0 if $status && $status eq 401;
}

# TODO: give plugins a chance - create a callback to intercept cacheability

Expand Down

0 comments on commit 7535172

Please sign in to comment.