mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 01:35:28 +03:00
Merge pull request #1020 from atomgomba/feature-firmware-caching
FirmwareCache: add method to manually purge cache and maintenance
This commit is contained in:
commit
eaddb59e48
2 changed files with 37 additions and 4 deletions
|
@ -81,9 +81,11 @@ let FirmwareCache = (function () {
|
||||||
let cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey)
|
let cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey)
|
||||||
? obj[cacheKey]
|
? obj[cacheKey]
|
||||||
: null;
|
: null;
|
||||||
|
if (cached === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
chrome.storage.local.remove(cacheKey, () => {
|
chrome.storage.local.remove(cacheKey, () => {
|
||||||
onRemoveFromCache(cached.release);
|
onRemoveFromCache(cached.release);
|
||||||
console.debug("Cache data removed: " + cacheKey);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return oldest;
|
return oldest;
|
||||||
|
@ -139,7 +141,6 @@ let FirmwareCache = (function () {
|
||||||
hexdata: hexdata,
|
hexdata: hexdata,
|
||||||
};
|
};
|
||||||
chrome.storage.local.set(obj, () => {
|
chrome.storage.local.set(obj, () => {
|
||||||
console.info("Release put to cache: " + key);
|
|
||||||
onPutToCache(release);
|
onPutToCache(release);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -168,6 +169,35 @@ let FirmwareCache = (function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all cached data
|
||||||
|
*/
|
||||||
|
function invalidate() {
|
||||||
|
if (!journalLoaded) {
|
||||||
|
console.warn("Cache journal not yet loaded");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
let cacheKeys = [];
|
||||||
|
for (let key of journal.keys()) {
|
||||||
|
cacheKeys.push(withCachePrefix(key));
|
||||||
|
}
|
||||||
|
chrome.storage.local.get(cacheKeys, obj => {
|
||||||
|
if (typeof obj !== "object") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let cacheKey of cacheKeys) {
|
||||||
|
if (obj.hasOwnProperty(cacheKey)) {
|
||||||
|
/** @type {CacheItem} */
|
||||||
|
let item = obj[cacheKey];
|
||||||
|
onRemoveFromCache(item.release);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chrome.storage.local.remove(cacheKeys);
|
||||||
|
});
|
||||||
|
journal.clear();
|
||||||
|
JournalStorage.persist(journal.toJSON());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Descriptor} release
|
* @param {Descriptor} release
|
||||||
*/
|
*/
|
||||||
|
@ -175,6 +205,7 @@ let FirmwareCache = (function () {
|
||||||
if (typeof onPutToCacheCallback === "function") {
|
if (typeof onPutToCacheCallback === "function") {
|
||||||
onPutToCacheCallback(release);
|
onPutToCacheCallback(release);
|
||||||
}
|
}
|
||||||
|
console.info("Release put to cache: " + keyOf(release));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,6 +215,7 @@ let FirmwareCache = (function () {
|
||||||
if (typeof onRemoveFromCacheCallback === "function") {
|
if (typeof onRemoveFromCacheCallback === "function") {
|
||||||
onRemoveFromCacheCallback(release);
|
onRemoveFromCacheCallback(release);
|
||||||
}
|
}
|
||||||
|
console.debug("Cache data removed: " + keyOf(release));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,9 +240,10 @@ let FirmwareCache = (function () {
|
||||||
load: () => {
|
load: () => {
|
||||||
JournalStorage.load(onEntriesLoaded);
|
JournalStorage.load(onEntriesLoaded);
|
||||||
},
|
},
|
||||||
flush: () => {
|
unload: () => {
|
||||||
JournalStorage.persist(journal.toJSON());
|
JournalStorage.persist(journal.toJSON());
|
||||||
journal.clear();
|
journal.clear();
|
||||||
},
|
},
|
||||||
|
invalidate: invalidate,
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -545,7 +545,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
|
|
||||||
TABS.firmware_flasher.cleanup = function (callback) {
|
TABS.firmware_flasher.cleanup = function (callback) {
|
||||||
PortHandler.flush_callbacks();
|
PortHandler.flush_callbacks();
|
||||||
FirmwareCache.flush();
|
FirmwareCache.unload();
|
||||||
|
|
||||||
// unbind "global" events
|
// unbind "global" events
|
||||||
$(document).unbind('keypress');
|
$(document).unbind('keypress');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue