Skip to content

Commit

Permalink
Use prime number to generate cache-bypass token
Browse files Browse the repository at this point in the history
Related discussion:
- 048bfd251c9b#r37972005

From <https://github.com/gwarser>:

> 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.
  • Loading branch information
gorhill committed Mar 22, 2020
1 parent 086aece commit f520423
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/js/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '?';
Expand Down

0 comments on commit f520423

Please sign in to comment.