Skip to content

Commit

Permalink
feat(dropdown): simple temporary cache clear
Browse files Browse the repository at this point in the history
Adds another behavior "clear cache" which temporary disables the api cache at the next remote call.
This allows for just temporary clearing the cache if "apiSettings; {cache: false}" (for no cache at all) is not desired
  • Loading branch information
lubber-de authored Feb 26, 2023
1 parent 9f9137a commit e19bdc5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
selectObserver,
menuObserver,
classObserver,
module
module,
tempDisableApiCache = false
;

module = {
Expand Down Expand Up @@ -869,11 +870,12 @@
if (!$module.api('get request')) {
module.setup.api();
}
apiSettings = $.extend(true, {}, apiSettings, settings.apiSettings, apiCallbacks);
apiSettings = $.extend(true, {}, apiSettings, settings.apiSettings, apiCallbacks, tempDisableApiCache ? { cache: false } : {});
$module
.api('setting', apiSettings)
.api('query')
;
tempDisableApiCache = false;
},

filterItems: function (query) {
Expand Down Expand Up @@ -2399,6 +2401,11 @@
module.set.value('', null, null, preventChangeTrigger);
},

clearCache: function () {
module.debug('Clearing API cache once');
tempDisableApiCache = true;
},

scrollPage: function (direction, $selectedItem) {
var
$currentItem = $selectedItem || module.get.selectedItem(),
Expand Down Expand Up @@ -3449,7 +3456,7 @@
return settings.apiSettings && module.can.useAPI();
},
noApiCache: function () {
return settings.apiSettings && !settings.apiSettings.cache;
return tempDisableApiCache || (settings.apiSettings && !settings.apiSettings.cache);
},
single: function () {
return !module.is.multiple();
Expand Down

0 comments on commit e19bdc5

Please sign in to comment.