-
-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathcache.ts
More file actions
56 lines (46 loc) · 1.67 KB
/
cache.ts
File metadata and controls
56 lines (46 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import process from 'node:process'
import { defineNuxtModule, useRuntimeConfig } from 'nuxt/kit'
import { provider } from 'std-env'
// Storage key for fetch cache - must match shared/utils/fetch-cache-config.ts
const FETCH_CACHE_STORAGE_BASE = 'fetch-cache'
// Storage key for payload cache - must match server/plugins/payload-cache.ts
const PAYLOAD_CACHE_STORAGE_KEY = 'payload-cache'
export default defineNuxtModule({
meta: {
name: 'vercel-cache',
},
setup(_, nuxt) {
if (provider !== 'vercel') {
return
}
const config = useRuntimeConfig()
nuxt.hook('nitro:config', nitroConfig => {
nitroConfig.storage = nitroConfig.storage || {}
const upstash = {
driver: 'upstash' as const,
url: config.upstash.redisRestUrl,
token: config.upstash.redisRestToken,
}
if (process.env.RUNTIME_CACHE) {
// Main cache storage (for defineCachedFunction, etc.)
nitroConfig.storage.cache = {
...nitroConfig.storage.cache,
driver: 'vercel-runtime-cache',
}
// Fetch cache storage (for SWR fetch caching)
nitroConfig.storage[FETCH_CACHE_STORAGE_BASE] = {
...nitroConfig.storage[FETCH_CACHE_STORAGE_BASE],
driver: 'vercel-runtime-cache',
}
// Payload cache storage (for runtime payload caching)
nitroConfig.storage[PAYLOAD_CACHE_STORAGE_KEY] = {
...nitroConfig.storage[PAYLOAD_CACHE_STORAGE_KEY],
driver: 'vercel-runtime-cache',
}
}
const env = process.env.VERCEL_ENV
nitroConfig.storage.atproto =
env === 'production' ? upstash : { driver: 'vercel-runtime-cache' }
})
},
})