-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.js
66 lines (63 loc) · 2.1 KB
/
cache.js
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
57
58
59
60
61
62
63
64
65
66
export const PAGE_CACHE_HANDLER = ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 60,
},
})
}
export const API_CACHE_HANDLER = ({ cache, proxy }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60,
// Cache responses even if they contain cache-control: private header
// https://docs.edg.io/guides/caching#private
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
forcePrivateCaching: true,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
proxy('api', { path: ':path*' })
}
export const IMAGE_CACHE_HANDLER = ({ cache, proxy }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60,
// Cache responses even if they contain cache-control: private header
// https://docs.edg.io/guides/caching#private
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
forcePrivateCaching: true,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
proxy('image', { path: '/' })
}
export const ASSET_CACHE_HANDLER = ({ removeUpstreamResponseHeader, cache }) => {
// Remove the cache-control header coming in from the Next.js app,
// and remove the set-cookie header coming in from the Next.js app,
// this is to ensure that the response is cacheable
removeUpstreamResponseHeader('set-cookie')
removeUpstreamResponseHeader('cache-control')
// Set the caching values
cache({
edge: {
// Save the response(s) [whether stale or updated] in the edge POP for a year
maxAgeSeconds: 60 * 60 * 24 * 365,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
}