mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-20 17:01:47 +03:00
Fixed Cache.set
work
This commit is contained in:
parent
6983ca6c36
commit
5abd8d788b
1 changed files with 22 additions and 18 deletions
|
@ -24,17 +24,19 @@ export default class Cache
|
|||
return new Promise(async (resolve) => {
|
||||
if (this.cache !== null && this.cache[name] !== undefined)
|
||||
{
|
||||
const expired = this.cache[name].ttl !== null ? Date.now() > this.cache[name].ttl * 1000 : false;
|
||||
|
||||
Debug.log({
|
||||
function: 'Cache.get',
|
||||
message: [
|
||||
`Resolved ${this.cache[name].expired ? 'expired' : 'unexpired'} hot cache record`,
|
||||
`Resolved ${expired ? 'expired' : 'unexpired'} hot cache record`,
|
||||
`[name] ${name}`,
|
||||
`[value]: ${JSON.stringify(this.cache[name].value)}`
|
||||
]
|
||||
});
|
||||
|
||||
resolve({
|
||||
expired: this.cache[name].ttl !== null ? Date.now() > this.cache[name].ttl * 1000 : false,
|
||||
expired: expired,
|
||||
value: this.cache[name].value
|
||||
});
|
||||
}
|
||||
|
@ -82,22 +84,6 @@ export default class Cache
|
|||
{
|
||||
return new Promise((resolve) => {
|
||||
constants.paths.cache.then((cacheFile) => {
|
||||
if (this.cache === null)
|
||||
{
|
||||
Neutralino.filesystem.readFile(cacheFile)
|
||||
.then((cacheRaw) =>
|
||||
{
|
||||
this.cache = JSON.parse(cacheRaw);
|
||||
|
||||
writeCache();
|
||||
})
|
||||
.catch(() => {
|
||||
this.cache = {};
|
||||
|
||||
writeCache();
|
||||
});
|
||||
}
|
||||
|
||||
const writeCache = () => {
|
||||
Debug.log({
|
||||
function: 'Cache.set',
|
||||
|
@ -116,6 +102,24 @@ export default class Cache
|
|||
Neutralino.filesystem.writeFile(cacheFile, JSON.stringify(this.cache))
|
||||
.then(() => resolve());
|
||||
};
|
||||
|
||||
if (this.cache === null)
|
||||
{
|
||||
Neutralino.filesystem.readFile(cacheFile)
|
||||
.then((cacheRaw) =>
|
||||
{
|
||||
this.cache = JSON.parse(cacheRaw);
|
||||
|
||||
writeCache();
|
||||
})
|
||||
.catch(() => {
|
||||
this.cache = {};
|
||||
|
||||
writeCache();
|
||||
});
|
||||
}
|
||||
|
||||
else writeCache();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue