aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/cache/cache.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/cache/cache.ts')
-rw-r--r--server/middlewares/cache/cache.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/middlewares/cache/cache.ts b/server/middlewares/cache/cache.ts
new file mode 100644
index 000000000..48162a0ae
--- /dev/null
+++ b/server/middlewares/cache/cache.ts
@@ -0,0 +1,32 @@
1import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
2import { Redis } from '../../lib/redis'
3import { ApiCache, APICacheOptions } from './shared'
4
5// Ensure Redis is initialized
6Redis.Instance.init()
7
8const defaultOptions: APICacheOptions = {
9 excludeStatus: [
10 HttpStatusCode.FORBIDDEN_403,
11 HttpStatusCode.NOT_FOUND_404
12 ]
13}
14
15function cacheRoute (duration: string) {
16 const instance = new ApiCache(defaultOptions)
17
18 return instance.buildMiddleware(duration)
19}
20
21function cacheRouteFactory (options: APICacheOptions) {
22 const instance = new ApiCache({ ...defaultOptions, ...options })
23
24 return instance.buildMiddleware.bind(instance)
25}
26
27// ---------------------------------------------------------------------------
28
29export {
30 cacheRoute,
31 cacheRouteFactory
32}