fix: add cleaner cron impl

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2024-11-11 23:18:13 +08:00
parent 0ce6546d7f
commit faae74b8ba
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 12 additions and 5 deletions

View File

@ -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)
}
}
}

View File

@ -154,6 +154,7 @@ const AppCacheLimit = () => {
const byteSize = (await tipcClient?.getCacheSize()) ?? 0
return Math.round(byteSize / 1024 / 1024)
},
refetchOnMount: "always",
})
const {
data: cacheLimit,