|
| 1 | +// Type definitions for Next.js cacheLife configs |
| 2 | + |
| 3 | +declare module 'next/cache' { |
| 4 | + export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache' |
| 5 | + export { |
| 6 | + updateTag, |
| 7 | + revalidateTag, |
| 8 | + revalidatePath, |
| 9 | + refresh, |
| 10 | + } from 'next/dist/server/web/spec-extension/revalidate' |
| 11 | + export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' |
| 12 | + |
| 13 | + |
| 14 | + /** |
| 15 | + * Cache this `"use cache"` for a timespan defined by the `"default"` profile. |
| 16 | + * ``` |
| 17 | + * stale: 300 seconds (5 minutes) |
| 18 | + * revalidate: 900 seconds (15 minutes) |
| 19 | + * expire: never |
| 20 | + * ``` |
| 21 | + * |
| 22 | + * This cache may be stale on clients for 5 minutes before checking with the server. |
| 23 | + * If the server receives a new request after 15 minutes, start revalidating new values in the background. |
| 24 | + * It lives for the maximum age of the server cache. If this entry has no traffic for a while, it may serve an old value the next request. |
| 25 | + */ |
| 26 | + export function cacheLife(profile: "default"): void |
| 27 | + |
| 28 | + /** |
| 29 | + * Cache this `"use cache"` for a timespan defined by the `"seconds"` profile. |
| 30 | + * ``` |
| 31 | + * stale: 30 seconds |
| 32 | + * revalidate: 1 seconds |
| 33 | + * expire: 60 seconds (1 minute) |
| 34 | + * ``` |
| 35 | + * |
| 36 | + * This cache may be stale on clients for 30 seconds before checking with the server. |
| 37 | + * If the server receives a new request after 1 seconds, start revalidating new values in the background. |
| 38 | + * If this entry has no traffic for 1 minute it will expire. The next request will recompute it. |
| 39 | + */ |
| 40 | + export function cacheLife(profile: "seconds"): void |
| 41 | + |
| 42 | + /** |
| 43 | + * Cache this `"use cache"` for a timespan defined by the `"minutes"` profile. |
| 44 | + * ``` |
| 45 | + * stale: 300 seconds (5 minutes) |
| 46 | + * revalidate: 60 seconds (1 minute) |
| 47 | + * expire: 3600 seconds (1 hour) |
| 48 | + * ``` |
| 49 | + * |
| 50 | + * This cache may be stale on clients for 5 minutes before checking with the server. |
| 51 | + * If the server receives a new request after 1 minute, start revalidating new values in the background. |
| 52 | + * If this entry has no traffic for 1 hour it will expire. The next request will recompute it. |
| 53 | + */ |
| 54 | + export function cacheLife(profile: "minutes"): void |
| 55 | + |
| 56 | + /** |
| 57 | + * Cache this `"use cache"` for a timespan defined by the `"hours"` profile. |
| 58 | + * ``` |
| 59 | + * stale: 300 seconds (5 minutes) |
| 60 | + * revalidate: 3600 seconds (1 hour) |
| 61 | + * expire: 86400 seconds (1 day) |
| 62 | + * ``` |
| 63 | + * |
| 64 | + * This cache may be stale on clients for 5 minutes before checking with the server. |
| 65 | + * If the server receives a new request after 1 hour, start revalidating new values in the background. |
| 66 | + * If this entry has no traffic for 1 day it will expire. The next request will recompute it. |
| 67 | + */ |
| 68 | + export function cacheLife(profile: "hours"): void |
| 69 | + |
| 70 | + /** |
| 71 | + * Cache this `"use cache"` for a timespan defined by the `"days"` profile. |
| 72 | + * ``` |
| 73 | + * stale: 300 seconds (5 minutes) |
| 74 | + * revalidate: 86400 seconds (1 day) |
| 75 | + * expire: 604800 seconds (1 week) |
| 76 | + * ``` |
| 77 | + * |
| 78 | + * This cache may be stale on clients for 5 minutes before checking with the server. |
| 79 | + * If the server receives a new request after 1 day, start revalidating new values in the background. |
| 80 | + * If this entry has no traffic for 1 week it will expire. The next request will recompute it. |
| 81 | + */ |
| 82 | + export function cacheLife(profile: "days"): void |
| 83 | + |
| 84 | + /** |
| 85 | + * Cache this `"use cache"` for a timespan defined by the `"weeks"` profile. |
| 86 | + * ``` |
| 87 | + * stale: 300 seconds (5 minutes) |
| 88 | + * revalidate: 604800 seconds (1 week) |
| 89 | + * expire: 2592000 seconds (1 month) |
| 90 | + * ``` |
| 91 | + * |
| 92 | + * This cache may be stale on clients for 5 minutes before checking with the server. |
| 93 | + * If the server receives a new request after 1 week, start revalidating new values in the background. |
| 94 | + * If this entry has no traffic for 1 month it will expire. The next request will recompute it. |
| 95 | + */ |
| 96 | + export function cacheLife(profile: "weeks"): void |
| 97 | + |
| 98 | + /** |
| 99 | + * Cache this `"use cache"` for a timespan defined by the `"max"` profile. |
| 100 | + * ``` |
| 101 | + * stale: 300 seconds (5 minutes) |
| 102 | + * revalidate: 2592000 seconds (1 month) |
| 103 | + * expire: 31536000 seconds (365 days) |
| 104 | + * ``` |
| 105 | + * |
| 106 | + * This cache may be stale on clients for 5 minutes before checking with the server. |
| 107 | + * If the server receives a new request after 1 month, start revalidating new values in the background. |
| 108 | + * If this entry has no traffic for 365 days it will expire. The next request will recompute it. |
| 109 | + */ |
| 110 | + export function cacheLife(profile: "max"): void |
| 111 | + |
| 112 | + /** |
| 113 | + * Cache this `"use cache"` using a custom timespan. |
| 114 | + * ``` |
| 115 | + * stale: ... // seconds |
| 116 | + * revalidate: ... // seconds |
| 117 | + * expire: ... // seconds |
| 118 | + * ``` |
| 119 | + * |
| 120 | + * This is similar to Cache-Control: max-age=`stale`,s-max-age=`revalidate`,stale-while-revalidate=`expire-revalidate` |
| 121 | + * |
| 122 | + * If a value is left out, the lowest of other cacheLife() calls or the default, is used instead. |
| 123 | + */ |
| 124 | + export function cacheLife(profile: { |
| 125 | + /** |
| 126 | + * This cache may be stale on clients for ... seconds before checking with the server. |
| 127 | + */ |
| 128 | + stale?: number, |
| 129 | + /** |
| 130 | + * If the server receives a new request after ... seconds, start revalidating new values in the background. |
| 131 | + */ |
| 132 | + revalidate?: number, |
| 133 | + /** |
| 134 | + * If this entry has no traffic for ... seconds it will expire. The next request will recompute it. |
| 135 | + */ |
| 136 | + expire?: number |
| 137 | + }): void |
| 138 | + |
| 139 | + |
| 140 | + import { cacheTag } from 'next/dist/server/use-cache/cache-tag' |
| 141 | + export { cacheTag } |
| 142 | + |
| 143 | + export const unstable_cacheTag: typeof cacheTag |
| 144 | + export const unstable_cacheLife: typeof cacheLife |
| 145 | +} |
0 commit comments