mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
ELECTRON-788: add clear cache functionality (#506)
* ELECTRON-788: clean cache on bad exits A few customers have reported that the cache gets corrupted when the app is not exited cleanly. And, upon the next start, we get cache_read_failures. This fix adds an extra check during startup and exit to check if the app was exited cleanly and deletes the corrupted cache folder accordingly during startup. * ELECTRON-788: add menu item, use electron session cache clear logic Adds a new menu item to clear cache and reload the app. Also remove the old logic of deleting the cache folder manually and use electron session api to clear the cache. * ELECTRON-788: refactor code
This commit is contained in:
committed by
GitHub
parent
d1009a2326
commit
628b05d46b
39
js/cacheHandler/index.js
Normal file
39
js/cacheHandler/index.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const fs = require('fs');
|
||||
const nodePath = require('path');
|
||||
const electron = require('electron');
|
||||
|
||||
const log = require('../log.js');
|
||||
const logLevels = require('../enums/logLevels.js');
|
||||
|
||||
const cacheCheckFilename = 'CacheCheck';
|
||||
const cacheCheckFilePath = nodePath.join(electron.app.getPath('userData'), cacheCheckFilename);
|
||||
|
||||
function handleCacheFailureCheckOnStartup() {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
|
||||
if (fs.existsSync(cacheCheckFilePath)) {
|
||||
log.send(logLevels.INFO, `Cache check file exists, so not clearing cache!`);
|
||||
fs.unlinkSync(cacheCheckFilePath);
|
||||
resolve();
|
||||
} else {
|
||||
log.send(logLevels.INFO, `Cache check file does not exist, we are clearing the cache!`);
|
||||
electron.session.defaultSession.clearCache(() => {
|
||||
log.send(logLevels.INFO, `Cleared cache!`);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function handleCacheFailureCheckOnExit() {
|
||||
log.send(logLevels.INFO, `Clean exit! Creating cache check file!`);
|
||||
fs.writeFileSync(cacheCheckFilePath, "");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
handleCacheFailureCheckOnStartup: handleCacheFailureCheckOnStartup,
|
||||
handleCacheFailureCheckOnExit: handleCacheFailureCheckOnExit
|
||||
};
|
Reference in New Issue
Block a user