From f5204235b70f2d23605190bedce8e4bbf00966ba Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 22 Mar 2020 11:31:06 -0400 Subject: [PATCH] Use prime number to generate cache-bypass token Related discussion: - https://github.com/gorhill/uBlock/commit/048bfd251c9b#r37972005 From : > I think this should be "modulo prime", not 12. > If someone always turn on PC in "8am" there is > a slight chance to hit cache. --- src/js/assets.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/js/assets.js b/src/js/assets.js index 899af85de..cf1eb98cc 100644 --- a/src/js/assets.js +++ b/src/js/assets.js @@ -161,11 +161,14 @@ api.fetchText = async function(url) { // https://github.com/uBlockOrigin/uBlock-issues/issues/682#issuecomment-515197130 // Provide filter list authors a way to completely bypass // the browser cache. + // https://github.com/gorhill/uBlock/commit/048bfd251c9b#r37972005 + // Use modulo prime numbers to avoid generating the same token at the + // same time across different days. if ( isExternal ) { const cacheBypassToken = µBlock.hiddenSettings.updateAssetBypassBrowserCache - ? Math.floor(Date.now() / 1000) % 86400 - : Math.floor(Date.now() / 3600000) % 12; + ? Math.floor(Date.now() / 1000) % 86413 + : Math.floor(Date.now() / 3600000) % 13; const queryValue = `_=${cacheBypassToken}`; if ( actualUrl.indexOf('?') === -1 ) { actualUrl += '?';