jenkins-bot has submitted this change and it was merged.

Change subject: wmfstatic: Allow longer client-side caching of 'nohash' 
responses
......................................................................


wmfstatic: Allow longer client-side caching of 'nohash' responses

Currently nohash is treated as a penalty way (only 5 minutes).
In reality, while it's nice to strive for having all urls hash-validated,
at the moment this isn't feasible because there are many circumstances in
which we can't (yet) produce or transport a hash to the code making the url.

Also, there are also valid use cases for explicitly not wanting to pin a
url to a specific verison fo a file when that would cause different pages
to display different version of the file (due to static caching of html
output,e.g. the "Powered by" logo in the footer and other interface elements
not provided by a central stylesheet).

An exception to the above is the site logo because that isn't linked from HTML.
It's referenced by a stylesheet that itself is centrally loaded and invalidated
(so it never varies by page).

For in-HTML images (such as the footer images and other interface images), one
doesn't want to hardcode the file version.

Recognise this by bumping the allowed cache age for clients from 5min to 24h.
I'm keeping the server-side max-age at 5 min for now to allow allow deployments
to quickly affect users with no prior cache. It's cheap enough to have the
backends bounce a 304 Not Modified around every few minutes for hot file paths
(similar to how it does now).

While this does increase max-age for some urls, it effectively still shortens
it compared to how it was before wmfstatic existed. Previously these urls were
always cached for a year unconditonally. And the majority of wikis isn't using
wmfstatic yet.

Change-Id: Iee2f359cf474347b03360e1da97c605c16aebbc6
---
M w/static.php
1 file changed, 12 insertions(+), 12 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  Ori.livneh: Looks good to me, but someone else must approve
  BBlack: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/w/static.php b/w/static.php
index d08445f..6ac6d86 100644
--- a/w/static.php
+++ b/w/static.php
@@ -21,7 +21,7 @@
  *
  * StatD metrics:
  *
- * - wmfstatic.success.<cacheMaxAge>.<branchName>
+ * - wmfstatic.success.<responseType>
  * - wmfstatic.notfound
  * - wmfstatic.fallback
  */
@@ -38,9 +38,9 @@
  * Stream file from disk to web response
  * Based on StreamFile::stream()
  * @param string $filePath
- * @param int $maxAge Time in seconds to cache successful response
+ * @param string $responseType Cache control for successful repsonse (one of 
'short' or 'long')
  */
-function wmfStaticStreamFile( $filePath, $maxAge = 300 ) {
+function wmfStaticStreamFile( $filePath, $responseType = 'nohash' ) {
        $stat = stat( $filePath );
        if ( !$stat ) {
                header( 'HTTP/1.1 404 Not Found' );
@@ -61,8 +61,13 @@
        }
        header( 'Last-Modified: ' . wfTimestamp( TS_RFC2822, $stat['mtime'] ) );
        header( "Content-Type: $ctype" );
-       $maxAge = (int) $maxAge;
-       header( "Cache-Control: public, s-maxage=$maxAge, max-age=$maxAge" );
+       if ( $responseType === 'verified' ) {
+               // 1 year (365 * 24 * 3600) on proxy servers and clients
+               header( 'Cache-Control: public, s-maxage=31536000, 
max-age=31536000' );
+       } else {
+               // 5 min (5 * 50) on proxy servers and 24 hours (24 * 3600) on 
clients
+               header( 'Cache-Control: public, s-maxage=300, must-revalidate, 
max-age=86400' );
+       }
 
        if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
                $ims = preg_replace( '/;.*$/', '', 
$_SERVER['HTTP_IF_MODIFIED_SINCE'] );
@@ -106,13 +111,9 @@
        }
        $path = substr( $uriPath, strlen( $urlPrefix ) );
 
-       $cacheLong = 31536000; // 1 year (365 * 24 * 3600)
-       $cacheShort = 300; // 5 minutes (5 * 60)
-
        // Validation hash
        $urlHash = isset( $_SERVER['QUERY_STRING'] ) ? $_SERVER['QUERY_STRING'] 
: false;
        $fallback = false;
-       $maxAge = $cacheShort;
        $responseType = 'nohash';
 
        // Get branch dirs and sort with newest first
@@ -164,11 +165,10 @@
                                continue;
                        }
                        // Cache hash-validated responses for long
-                       $maxAge = $cacheLong;
                        $responseType = 'verified';
                }
 
-               wmfStaticStreamFile( $filePath, $maxAge );
+               wmfStaticStreamFile( $filePath, $responseType );
                $stats->increment( "wmfstatic.success.$responseType" );
                return;
        }
@@ -181,7 +181,7 @@
                return;
        }
 
-       wmfStaticStreamFile( "$fallback/$path", $maxAge );
+       wmfStaticStreamFile( "$fallback/$path", $responseType );
        $stats->increment( 'wmfstatic.mismatch' );
        return;
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/272793
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iee2f359cf474347b03360e1da97c605c16aebbc6
Gerrit-PatchSet: 1
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: BBlack <bbl...@wikimedia.org>
Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to