From 44bc92dfdd8f7dcb3345c15bdaeae3a68a667743 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 13 Feb 2019 07:37:03 +0800 Subject: [PATCH] MDL-64835 JS: Stop using the jsrev in the jsrevPrefix We only use the jsrevPrefix to determine if the cache should be invalidated, but the prefix that we were using is based on the new jsrev. For example, the jsrevPrefix will be: hash(wwwroot + '/ + config.jsrev) + '/jsrev' Where config.jsrev is the _current_ (new) jsrev. As a result when searching for the jsrev used to store the data which is currently in the storage cache, no key is returned, and we instead set an 'initial' value and the cache is not cleared This patch changes the jsrevPrefix to be: hash(wwwroot) + '/jsrev' Since the wwwroot does not change, the key remains static for the current site. As a result, when the jsrev is bumped via a Moodle cache purge, we are able to correctly fetch the old jsrev from the cache, determine that the jsrev has changed, and purge the cache. --- lib/amd/build/storagewrapper.min.js | 2 +- lib/amd/src/storagewrapper.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/amd/build/storagewrapper.min.js b/lib/amd/build/storagewrapper.min.js index 01fd0c64179..edc052e7304 100644 --- a/lib/amd/build/storagewrapper.min.js +++ b/lib/amd/build/storagewrapper.min.js @@ -1 +1 @@ -define(["core/config"],function(a){var b=function(b){this.storage=b,this.supported=this.detectSupport(),this.hashSource=a.wwwroot+"/"+a.jsrev,this.hash=this.hashString(this.hashSource),this.prefix=this.hash+"/",this.jsrevPrefix=this.hash+"/jsrev"};return b.prototype.detectSupport=function(){if(a.jsrev==-1)return!1;if("undefined"==typeof this.storage)return!1;var b="test";try{return null!==this.storage&&(this.storage.setItem(b,"1"),this.storage.removeItem(b),!0)}catch(c){return!1}},b.prototype.prefixKey=function(a){return this.prefix+a},b.prototype.validateCache=function(){var b=this.storage.getItem(this.jsrevPrefix);if(null===b)return void this.storage.setItem(this.jsrevPrefix,a.jsrev);var c=a.jsrev;c!=b&&(this.storage.clear(),this.storage.setItem(this.jsrevPrefix,a.jsrev))},b.prototype.hashString=function(a){var b,c,d,e=0;if(0===a.length)return e;for(b=0,d=a.length;b