mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-19 14:25:14 +03:00
FirmwareCache: add method to manually purge cache and maintenance
This commit is contained in:
parent
1e8cf6fc2d
commit
65e49e5896
1 changed files with 31 additions and 2 deletions
|
@ -81,9 +81,11 @@ let FirmwareCache = (function () {
|
|||
let cached = typeof obj === "object" && obj.hasOwnProperty(cacheKey)
|
||||
? obj[cacheKey]
|
||||
: null;
|
||||
if (cached === null) {
|
||||
return;
|
||||
}
|
||||
chrome.storage.local.remove(cacheKey, () => {
|
||||
onRemoveFromCache(cached.release);
|
||||
console.debug("Cache data removed: " + cacheKey);
|
||||
});
|
||||
});
|
||||
return oldest;
|
||||
|
@ -139,7 +141,6 @@ let FirmwareCache = (function () {
|
|||
hexdata: hexdata,
|
||||
};
|
||||
chrome.storage.local.set(obj, () => {
|
||||
console.info("Release put to cache: " + key);
|
||||
onPutToCache(release);
|
||||
});
|
||||
}
|
||||
|
@ -168,6 +169,31 @@ let FirmwareCache = (function () {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all cached data
|
||||
*/
|
||||
function destroy() {
|
||||
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
|
||||
*/
|
||||
|
@ -175,6 +201,7 @@ let FirmwareCache = (function () {
|
|||
if (typeof onPutToCacheCallback === "function") {
|
||||
onPutToCacheCallback(release);
|
||||
}
|
||||
console.info("Release put to cache: " + keyOf(release));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,6 +211,7 @@ let FirmwareCache = (function () {
|
|||
if (typeof onRemoveFromCacheCallback === "function") {
|
||||
onRemoveFromCacheCallback(release);
|
||||
}
|
||||
console.debug("Cache data removed: " + keyOf(release));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,5 +240,6 @@ let FirmwareCache = (function () {
|
|||
JournalStorage.persist(journal.toJSON());
|
||||
journal.clear();
|
||||
},
|
||||
destroy: destroy,
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue