From bfe25c7da57ee5d4e6bc816796c5fc03ebbdd303 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Tue, 16 Jun 2015 09:14:07 +0200 Subject: [PATCH] mblinks: make expiration optional Use a common default value of 90 days. --- bandcamp_importer.user.js | 2 +- discogs_importer.user.js | 2 +- encyclopedisque_importer.user.js | 2 +- lib/mblinks.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bandcamp_importer.user.js b/bandcamp_importer.user.js index 21bd69d..6d01a40 100644 --- a/bandcamp_importer.user.js +++ b/bandcamp_importer.user.js @@ -204,7 +204,7 @@ var BandcampImport = { $(document).ready(function () { MBImportStyle(); - var mblinks = new MBLinks('BCI_MBLINKS_CACHE', 7*24*60); // force refresh of cached links once a week + var mblinks = new MBLinks('BCI_MBLINKS_CACHE'); var release = BandcampImport.retrieveReleaseInfo(); LOGGER.info("Parsed release: ", release); diff --git a/discogs_importer.user.js b/discogs_importer.user.js index 3d8e40f..19329fd 100644 --- a/discogs_importer.user.js +++ b/discogs_importer.user.js @@ -37,7 +37,7 @@ if (DEBUG) { * - http://www.discogs.com/release/1566223 : Artist credit of tracks contains an ending ',' join phrase */ -var mblinks = new MBLinks('DISCOGS_MBLINKS_CACHE', 7*24*60, '1'); // force refresh of cached links once a week +var mblinks = new MBLinks('DISCOGS_MBLINKS_CACHE', false, '1'); $(document).ready(function(){ diff --git a/encyclopedisque_importer.user.js b/encyclopedisque_importer.user.js index 5a6d325..4141a52 100644 --- a/encyclopedisque_importer.user.js +++ b/encyclopedisque_importer.user.js @@ -14,7 +14,7 @@ // @require lib/mbimportstyle.js // ==/UserScript== -var mblinks = new MBLinks('ENCYLOPEDISQUE_MBLINKS_CACHE', 7*24*60); // force refresh of cached links once a week +var mblinks = new MBLinks('ENCYLOPEDISQUE_MBLINKS_CACHE'); $(document).ready(function() { MBImportStyle(); diff --git a/lib/mblinks.js b/lib/mblinks.js index 18e81fb..e58c234 100644 --- a/lib/mblinks.js +++ b/lib/mblinks.js @@ -14,7 +14,7 @@ // } // user_cache_key = textual key used to store cached data in local storage -// expiration = time in minutes before an entry is refreshed, value <= 0 disables cache reads +// expiration = time in minutes before an entry is refreshed, value <= 0 disables cache reads, if undefined or false, use defaults // version = optionnal version, to force creation of a cache (ie. when format of keys changes) var MBLinks = function (user_cache_key, expiration, version) { this.supports_local_storage = function () { @@ -57,7 +57,7 @@ var MBLinks = function (user_cache_key, expiration, version) { } }; this.cache = {}; - this.expirationMinutes = parseInt(expiration, 10); + this.expirationMinutes = ((typeof expiration != 'undefined' && expiration !== false) ? parseInt(expiration, 10) : 90*24*60); // default to 90 days var cache_version = 2; this.user_cache_key = user_cache_key; this.cache_key = this.user_cache_key + '-v' + cache_version + (typeof version != 'undefined' ? '.' + version : '');