mirror of https://github.com/wg-easy/wg-easy
7 changed files with 131 additions and 27 deletions
@ -7,5 +7,5 @@ |
|||||
"docs:preview": "docker run --rm -it -p 8080:8080 -v ./docs:/docs squidfunk/mkdocs-material serve -a 0.0.0.0:8080", |
"docs:preview": "docker run --rm -it -p 8080:8080 -v ./docs:/docs squidfunk/mkdocs-material serve -a 0.0.0.0:8080", |
||||
"scripts:version": "bash scripts/version.sh" |
"scripts:version": "bash scripts/version.sh" |
||||
}, |
}, |
||||
"packageManager": "[email protected].2" |
"packageManager": "[email protected].3" |
||||
} |
} |
||||
|
@ -61,5 +61,5 @@ |
|||||
"typescript": "^5.8.2", |
"typescript": "^5.8.2", |
||||
"vue-tsc": "^2.2.8" |
"vue-tsc": "^2.2.8" |
||||
}, |
}, |
||||
"packageManager": "[email protected].2" |
"packageManager": "[email protected].3" |
||||
} |
} |
||||
|
@ -0,0 +1,4 @@ |
|||||
|
export default definePermissionEventHandler('admin', 'any', async () => { |
||||
|
const result = await cachedGetIpInformation(); |
||||
|
return result; |
||||
|
}); |
@ -0,0 +1,29 @@ |
|||||
|
type Opts = { |
||||
|
/** |
||||
|
* Expiry time in milliseconds |
||||
|
*/ |
||||
|
expiry: number; |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Cache function for 1 hour |
||||
|
*/ |
||||
|
export function cacheFunction<T>(fn: () => T, { expiry }: Opts): () => T { |
||||
|
let cache: { value: T; expiry: number } | null = null; |
||||
|
|
||||
|
return (): T => { |
||||
|
const now = Date.now(); |
||||
|
|
||||
|
if (cache && cache.expiry > now) { |
||||
|
return cache.value; |
||||
|
} |
||||
|
|
||||
|
const result = fn(); |
||||
|
cache = { |
||||
|
value: result, |
||||
|
expiry: now + expiry, |
||||
|
}; |
||||
|
|
||||
|
return result; |
||||
|
}; |
||||
|
} |
Loading…
Reference in new issue