Permalink
Browse files

Item14202: Reduce pageCache activity by bots.

Allow the cache to ignore topic references for guest users. This can
greatly reduce the side of the cache dependencies table. Also make
the query parameter filter configurable and add fields:
 - validation_key is added after every login redirect to a topic.
 - redirectedfrom is added to the download cache.

Experimental for now.
  • Loading branch information...
1 parent 0893917 commit 1f7cce363719906047839da3353a527acd44049f @gac410 gac410 committed Oct 23, 2016
Showing with 71 additions and 11 deletions.
  1. +16 −0 core/lib/Foswiki.spec
  2. +52 −8 core/lib/Foswiki/PageCache.pm
  3. +2 −2 core/lib/Foswiki/Render.pm
  4. +1 −1 core/lib/Foswiki/Search.pm
View
@@ -1623,6 +1623,22 @@ $Foswiki::cfg{Cache}{RootDir} = '$Foswiki::cfg{WorkingDir}/cache';
$Foswiki::cfg{Cache}{WebDependencies} =
'WebRss, WebAtom, WebTopicList, WebIndex, WebSearch, WebSearchAdvanced';
+# **SELECT 'on','authenticated','off' LABEL="Track Topic Links" DISPLAY_IF="{Cache}{Enabled}" CHECK="iff:'{Cache}{Enabled}'"**
+# Select whether links to other topics should also be added to the page dependencies. Choose one of the following:
+#
+# * Set to =on= - the default - to record all topic links as dependencies
+# * Set to =authenticated= to record links for logged in users but ignore them for guests (and bots).
+# * Set to =off= to ignore all links (not recommended).
+# If a referenced topic is not added as a dependency, links may not reflect the correct status for missing or existing topics.
+# If you run a public wiki exposed to search bots, setting this to =authenticated= will reduce the size of the =foswiki_cache_deps= table.
+$Foswiki::cfg{Cache}{TrackInternalLinks} = 'on';
+
+# **STRING 80 LABEL="Query Param Filter" DISPLAY_IF="{Cache}{Enabled}" CHECK="iff:'{Cache}{Enabled}'"**
+# Comma-separated list of query params that should be ignored when building the cache key.
+# Common query parameters that do not effect the page content should be added to this list.
+# Entries in the list can contain regular expression meta characters. For example, the =_.*= entry matches any parameter beginning with underscore.
+$Foswiki::cfg{Cache}{ParamFilterList} = '_.*, cache_expire, cache_ignore, foswiki_redirect_cache, logout, redirectedfrom, refresh, topic, validation_key';
+
# **REGEX LABEL="Dependency Filter" DISPLAY_IF="{Cache}{Enabled}" CHECK="iff:'{Cache}{Enabled}'"**
# Exclude topics that match this regular expression from the dependency
# tracker.
@@ -165,13 +165,21 @@ m/^(_.*|VALIDATION|REMEMBER|FOSWIKISTRIKEONE.*|VALID_ACTIONS.*|BREADCRUMB_TRAIL|
# get cache_ignore pattern
my @ignoreParams = $request->multi_param("cache_ignore");
- push @ignoreParams,
- (
- "cache_expire", "cache_ignore",
- "_.*", "refresh",
- "foswiki_redirect_cache", "logout",
- "topic"
- );
+ if ( defined $Foswiki::cfg{Cache}{ParamFilterList} ) {
+ push @ignoreParams,
+ split( /\s*,\s*/, $Foswiki::cfg{Cache}{ParamFilterList} );
+ }
+ else {
+ # Defaults for older foswiki
+ push @ignoreParams,
+ (
+ "cache_expire", "cache_ignore",
+ "_.*", "refresh",
+ "foswiki_redirect_cache", "logout",
+ "validation_key", "topic",
+ "redirectedfrom"
+ );
+ }
my $ignoreParams = join( "|", @ignoreParams );
foreach my $key ( sort $request->multi_param() ) {
@@ -441,6 +449,42 @@ sub isCacheable {
=begin TML
+---++ ObjectMethod addTopicRef($web, $topic)
+
+Add a reference to a web.topic to the dependencies of the current page.
+
+Topic references, unlike hard dependencies, may cause internal links - WikiWords
+to render incorrectly unless the cache is cleared when the topic changes.
+(i.e, link to a missing topic, or render as a "new link" for a newly existing topic).
+
+This routine is configurable using {Cache}{TrackInternalLinks}. By default, it treats
+all topic references as simple dependencies. If disabled, link references are ignored,
+but if set to authenticated, links are tracked only for logged in users.
+
+=cut
+
+sub addTopicRef {
+ my ( $this, $webRef, $topicRef ) = @_;
+
+ #Foswiki::Func::writeDebug( "addTopicRef $webRef.$topicRef\n" ) if TRACE;
+
+ if ( defined $Foswiki::cfg{Cache}{TrackInternalLinks} ) {
+
+ return if ( $Foswiki::cfg{Cache}{TrackInternalLinks} eq 'off' );
+
+ my $session = $Foswiki::Plugins::SESSION;
+ return
+ unless (
+ ( $Foswiki::cfg{Cache}{TrackInternalLinks} eq 'authenticated' )
+ && $session->inContext('authenticated') );
+ }
+
+ return $this->addDependency( $webRef, $topicRef );
+
+}
+
+=begin TML
+
---++ ObjectMethod addDependency($web, $topic)
Add a web.topic to the dependencies of the current page
@@ -468,7 +512,7 @@ sub addDependency {
}
else {
- #Foswiki::Func::writeDebug("addDependency($depWeb.$depTopic)") if TRACE;
+#Foswiki::Func::writeDebug("addDependency($depWeb.$depTopic) by" . ( caller() )[1] ) if TRACE;
}
# collect them; defer writing them to the database til we cache this page
@@ -1308,7 +1308,7 @@ sub _renderWikiWord {
# add a dependency so that the page gets invalidated as soon as the
# topic is deleted
- $this->{session}->{cache}->addDependency( $web, $topic )
+ $this->{session}->{cache}->addTopicRef( $web, $topic )
if $Foswiki::cfg{Cache}{Enabled};
return _renderExistingWikiWord( $this, $web, $topic, $linkText, $anchor,
@@ -1324,7 +1324,7 @@ sub _renderWikiWord {
# add a dependency so that the page gets invalidated as soon as the
# WikiWord comes into existance
# Note we *ignore* the params if the target topic does not exist
- $this->{session}->{cache}->addDependency( $web, $topic )
+ $this->{session}->{cache}->addTopicRef( $web, $topic )
if $Foswiki::cfg{Cache}{Enabled};
return _renderNonExistingWikiWord( $this, $web, $topic, $linkText );
@@ -794,7 +794,7 @@ sub formatResults {
# add dependencies (TODO: unclear if this should be before the paging, or after the allowView - sadly, it can't be _in_ the infoCache)
if ( my $cache = $session->{cache} ) {
- $cache->addDependency( $web, $topic );
+ $cache->addTopicRef( $web, $topic );
}
my $topicMeta = $this->metacache->getMeta( $web, $topic );

0 comments on commit 1f7cce3

Please sign in to comment.