fix: add cleaner cron impl
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
parent
0ce6546d7f
commit
faae74b8ba
|
|
@ -92,6 +92,7 @@ const getCachedFilesRecursive = async (dir: string, result: string[] = []) => {
|
|||
}
|
||||
|
||||
let timer: any = null
|
||||
|
||||
export const clearCacheCronJob = () => {
|
||||
if (timer) {
|
||||
timer = clearInterval(timer)
|
||||
|
|
@ -121,11 +122,16 @@ export const clearCacheCronJob = () => {
|
|||
|
||||
let cleanedSize = 0
|
||||
for (const file of files) {
|
||||
const fileSize = statSync(file).size
|
||||
cleanedSize += fileSize
|
||||
if (cleanedSize >= shouldCleanSize) {
|
||||
logger.info(`Cleaned ${cleanedSize} bytes cache`)
|
||||
break
|
||||
try {
|
||||
const fileSize = statSync(file).size
|
||||
await fsp.rm(file, { force: true })
|
||||
cleanedSize += fileSize
|
||||
if (cleanedSize >= shouldCleanSize) {
|
||||
logger.info(`Cleaned ${cleanedSize} bytes cache`)
|
||||
break
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Failed to delete cache file ${file}:`, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ const AppCacheLimit = () => {
|
|||
const byteSize = (await tipcClient?.getCacheSize()) ?? 0
|
||||
return Math.round(byteSize / 1024 / 1024)
|
||||
},
|
||||
refetchOnMount: "always",
|
||||
})
|
||||
const {
|
||||
data: cacheLimit,
|
||||
|
|
|
|||
Loading…
Reference in New Issue