Skip to content

Commit

Permalink
fix: set ttl for appInfo to prevent permanent lockout
Browse files Browse the repository at this point in the history
  • Loading branch information
shuuji3 committed Mar 2, 2025
1 parent 4766467 commit 121a16f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/cache-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export default defineDriver((driver: Driver = memory()) => {

return driver.hasItem(key, {})
},
async setItem(key: string, value: any) {
async setItem(key: string, value: any, opts: any = {}) {
await Promise.all([
memoryDriver.setItem?.(key, value, {}),
driver.setItem?.(key, value, {}),
driver.setItem?.(key, value, opts),
])
},
async getItem(key: string) {
Expand Down
4 changes: 3 additions & 1 deletion server/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export async function getApp(origin: string, server: string) {
if (await storage.hasItem(key))
return (storage.getItem(key, {}) as Promise<AppInfo>)
const appInfo = await fetchAppInfo(origin, server)
await storage.setItem(key, appInfo)
// cache `appInfo` for 1 week to prevent permanent lockout
// note that `unstorage` supports `ttl` only for some storage drivers like cloudflare
await storage.setItem(key, appInfo, { ttl: 60 * 60 * 24 * 7 /* 1 week */ })
return appInfo
}
catch {
Expand Down

0 comments on commit 121a16f

Please sign in to comment.