[{"data":1,"prerenderedAt":2566},["ShallowReactive",2],{"navigation":3,"-docs-cache":389,"-docs-cache-surround":2561},[4,83,212,218,374,386],{"title":5,"path":6,"stem":7,"children":8,"icon":82},"","/docs","1.docs/1.index",[9,12,17,22,27,32,37,42,47,52,57,62,67,72,77],{"title":10,"path":6,"stem":7,"icon":11},"Introduction","i-lucide-compass",{"title":13,"path":14,"stem":15,"icon":16},"Quick Start","/docs/quick-start","1.docs/2.quick-start","i-lucide-zap",{"title":18,"path":19,"stem":20,"icon":21},"Renderer","/docs/renderer","1.docs/4.renderer","ri:layout-masonry-line",{"title":23,"path":24,"stem":25,"icon":26},"Routing","/docs/routing","1.docs/5.routing","ri:direction-line",{"title":28,"path":29,"stem":30,"icon":31},"Assets","/docs/assets","1.docs/50.assets","ri:image-2-line",{"title":33,"path":34,"stem":35,"icon":36},"Configuration","/docs/configuration","1.docs/50.configuration","ri:settings-3-line",{"title":38,"path":39,"stem":40,"icon":41},"Database","/docs/database","1.docs/50.database","ri:database-2-line",{"title":43,"path":44,"stem":45,"icon":46},"Lifecycle","/docs/lifecycle","1.docs/50.lifecycle","i-lucide-layers",{"title":48,"path":49,"stem":50,"icon":51},"Plugins","/docs/plugins","1.docs/50.plugins","ri:plug-line",{"title":53,"path":54,"stem":55,"icon":56},"Tasks","/docs/tasks","1.docs/50.tasks","codicon:run-all",{"title":58,"path":59,"stem":60,"icon":61},"Server Entry","/docs/server-entry","1.docs/6.server-entry","ri:server-line",{"title":63,"path":64,"stem":65,"icon":66},"Cache","/docs/cache","1.docs/7.cache","ri:speed-line",{"title":68,"path":69,"stem":70,"icon":71},"KV Storage","/docs/storage","1.docs/8.storage","carbon:datastore",{"title":73,"path":74,"stem":75,"icon":76},"Migration Guide","/docs/migration","1.docs/99.migration","ri:arrow-right-up-line",{"title":78,"path":79,"stem":80,"icon":81},"Nightly Channel","/docs/nightly","1.docs/99.nightly","ri:moon-fill","i-lucide-book-open",{"title":84,"path":85,"stem":86,"children":87,"icon":89},"Deploy","/deploy","2.deploy/0.index",[88,90,111],{"title":84,"path":85,"stem":86,"icon":89},"ri:upload-cloud-2-line",{"title":91,"path":92,"stem":93,"children":94,"page":110},"Runtimes","/deploy/runtimes","2.deploy/10.runtimes",[95,100,105],{"title":96,"path":97,"stem":98,"icon":99},"Node.js","/deploy/runtimes/node","2.deploy/10.runtimes/1.node","akar-icons:node-fill",{"title":101,"path":102,"stem":103,"icon":104},"Bun","/deploy/runtimes/bun","2.deploy/10.runtimes/bun","simple-icons:bun",{"title":106,"path":107,"stem":108,"icon":109},"Deno","/deploy/runtimes/deno","2.deploy/10.runtimes/deno","simple-icons:deno",false,{"title":112,"path":113,"stem":114,"children":115,"page":110},"Providers","/deploy/providers","2.deploy/20.providers",[116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208],{"title":117,"path":118,"stem":119},"Alwaysdata","/deploy/providers/alwaysdata","2.deploy/20.providers/alwaysdata",{"title":121,"path":122,"stem":123},"AWS Lambda","/deploy/providers/aws","2.deploy/20.providers/aws",{"title":125,"path":126,"stem":127},"AWS Amplify","/deploy/providers/aws-amplify","2.deploy/20.providers/aws-amplify",{"title":129,"path":130,"stem":131},"Azure","/deploy/providers/azure","2.deploy/20.providers/azure",{"title":133,"path":134,"stem":135},"Cleavr","/deploy/providers/cleavr","2.deploy/20.providers/cleavr",{"title":137,"path":138,"stem":139},"Cloudflare","/deploy/providers/cloudflare","2.deploy/20.providers/cloudflare",{"title":141,"path":142,"stem":143},"Deno Deploy","/deploy/providers/deno-deploy","2.deploy/20.providers/deno-deploy",{"title":145,"path":146,"stem":147},"DigitalOcean","/deploy/providers/digitalocean","2.deploy/20.providers/digitalocean",{"title":149,"path":150,"stem":151},"Firebase","/deploy/providers/firebase","2.deploy/20.providers/firebase",{"title":153,"path":154,"stem":155},"Flightcontrol","/deploy/providers/flightcontrol","2.deploy/20.providers/flightcontrol",{"title":157,"path":158,"stem":159},"Genezio","/deploy/providers/genezio","2.deploy/20.providers/genezio",{"title":161,"path":162,"stem":163},"GitHub Pages","/deploy/providers/github-pages","2.deploy/20.providers/github-pages",{"title":165,"path":166,"stem":167},"GitLab Pages","/deploy/providers/gitlab-pages","2.deploy/20.providers/gitlab-pages",{"title":169,"path":170,"stem":171},"Heroku","/deploy/providers/heroku","2.deploy/20.providers/heroku",{"title":173,"path":174,"stem":175},"IIS","/deploy/providers/iis","2.deploy/20.providers/iis",{"title":177,"path":178,"stem":179},"Koyeb","/deploy/providers/koyeb","2.deploy/20.providers/koyeb",{"title":181,"path":182,"stem":183},"Netlify","/deploy/providers/netlify","2.deploy/20.providers/netlify",{"title":185,"path":186,"stem":187},"Platform.sh","/deploy/providers/platform-sh","2.deploy/20.providers/platform-sh",{"title":189,"path":190,"stem":191},"Render.com","/deploy/providers/render","2.deploy/20.providers/render",{"title":193,"path":194,"stem":195},"StormKit","/deploy/providers/stormkit","2.deploy/20.providers/stormkit",{"title":197,"path":198,"stem":199},"Vercel","/deploy/providers/vercel","2.deploy/20.providers/vercel",{"title":201,"path":202,"stem":203},"Zeabur","/deploy/providers/zeabur","2.deploy/20.providers/zeabur",{"title":205,"path":206,"stem":207},"Zephyr Cloud","/deploy/providers/zephyr","2.deploy/20.providers/zephyr",{"title":209,"path":210,"stem":211},"Zerops","/deploy/providers/zerops","2.deploy/20.providers/zerops",{"title":213,"path":214,"stem":215,"children":216,"icon":36},"Config","/config","3.config/0.index",[217],{"title":213,"path":214,"stem":215,"icon":36},{"title":219,"path":220,"stem":221,"children":222,"icon":224},"Examples","/examples","4.examples/0.index",[223,225,230,235,240,245,249,254,259,264,269,274,279,283,288,292,296,301,306,311,316,321,326,331,336,341,345,350,355,359,364,369],{"title":219,"path":220,"stem":221,"icon":224},"i-lucide-folder-code",{"title":226,"path":227,"stem":228,"icon":229},"API Routes","/examples/api-routes","4.examples/api-routes","i-lucide-route",{"title":231,"path":232,"stem":233,"icon":234},"Auto Imports","/examples/auto-imports","4.examples/auto-imports","i-lucide-import",{"title":236,"path":237,"stem":238,"icon":239},"Cached Handler","/examples/cached-handler","4.examples/cached-handler","i-lucide-clock",{"title":241,"path":242,"stem":243,"icon":244},"Custom Error Handler","/examples/custom-error-handler","4.examples/custom-error-handler","i-lucide-alert-circle",{"title":38,"path":246,"stem":247,"icon":248},"/examples/database","4.examples/database","i-lucide-database",{"title":250,"path":251,"stem":252,"icon":253},"Elysia","/examples/elysia","4.examples/elysia","i-skill-icons-elysia-dark",{"title":255,"path":256,"stem":257,"icon":258},"Express","/examples/express","4.examples/express","i-simple-icons-express",{"title":260,"path":261,"stem":262,"icon":263},"Fastify","/examples/fastify","4.examples/fastify","i-simple-icons-fastify",{"title":265,"path":266,"stem":267,"icon":268},"Hello World","/examples/hello-world","4.examples/hello-world","i-lucide-sparkles",{"title":270,"path":271,"stem":272,"icon":273},"Hono","/examples/hono","4.examples/hono","i-logos-hono",{"title":275,"path":276,"stem":277,"icon":278},"Import Alias","/examples/import-alias","4.examples/import-alias","i-lucide-at-sign",{"title":280,"path":281,"stem":282,"icon":46},"Middleware","/examples/middleware","4.examples/middleware",{"title":284,"path":285,"stem":286,"icon":287},"Mono JSX","/examples/mono-jsx","4.examples/mono-jsx","i-lucide-brackets",{"title":289,"path":290,"stem":291,"icon":287},"Nano JSX","/examples/nano-jsx","4.examples/nano-jsx",{"title":48,"path":293,"stem":294,"icon":295},"/examples/plugins","4.examples/plugins","i-lucide-plug",{"title":297,"path":298,"stem":299,"icon":300},"Custom Renderer","/examples/renderer","4.examples/renderer","i-lucide-code",{"title":302,"path":303,"stem":304,"icon":305},"Runtime Config","/examples/runtime-config","4.examples/runtime-config","i-lucide-settings",{"title":307,"path":308,"stem":309,"icon":310},"Server Fetch","/examples/server-fetch","4.examples/server-fetch","i-lucide-arrow-right-left",{"title":312,"path":313,"stem":314,"icon":315},"Shiki","/examples/shiki","4.examples/shiki","i-lucide-highlighter",{"title":317,"path":318,"stem":319,"icon":320},"Virtual Routes","/examples/virtual-routes","4.examples/virtual-routes","i-lucide-box",{"title":322,"path":323,"stem":324,"icon":325},"Vite Nitro Plugin","/examples/vite-nitro-plugin","4.examples/vite-nitro-plugin","i-logos-vitejs",{"title":327,"path":328,"stem":329,"icon":330},"Vite RSC","/examples/vite-rsc","4.examples/vite-rsc","i-logos-react",{"title":332,"path":333,"stem":334,"icon":335},"Vite SSR HTML","/examples/vite-ssr-html","4.examples/vite-ssr-html","i-logos-html-5",{"title":337,"path":338,"stem":339,"icon":340},"SSR with Preact","/examples/vite-ssr-preact","4.examples/vite-ssr-preact","i-logos-preact",{"title":342,"path":343,"stem":344,"icon":330},"SSR with React","/examples/vite-ssr-react","4.examples/vite-ssr-react",{"title":346,"path":347,"stem":348,"icon":349},"SSR with SolidJS","/examples/vite-ssr-solid","4.examples/vite-ssr-solid","i-logos-solidjs-icon",{"title":351,"path":352,"stem":353,"icon":354},"SSR with TanStack Router","/examples/vite-ssr-tsr-react","4.examples/vite-ssr-tsr-react","i-simple-icons-tanstack",{"title":356,"path":357,"stem":358,"icon":354},"SSR with TanStack Start","/examples/vite-ssr-tss-react","4.examples/vite-ssr-tss-react",{"title":360,"path":361,"stem":362,"icon":363},"SSR with Vue Router","/examples/vite-ssr-vue-router","4.examples/vite-ssr-vue-router","i-logos-vue",{"title":365,"path":366,"stem":367,"icon":368},"Vite + tRPC","/examples/vite-trpc","4.examples/vite-trpc","i-simple-icons-trpc",{"title":370,"path":371,"stem":372,"icon":373},"WebSocket","/examples/websocket","4.examples/websocket","i-lucide-radio",{"title":375,"path":376,"stem":377,"children":378},"Blog","/blog","9.blog",[379,382],{"title":375,"path":376,"stem":380,"icon":381},"9.blog/index","i-lucide-file-text",{"title":383,"path":384,"stem":385,"icon":381},"Nitro v3 Beta is here!","/blog/v3-beta","9.blog/1.v3-beta",{"title":5,"path":387,"stem":388},"/","index",{"id":390,"title":63,"body":391,"description":2555,"extension":2556,"meta":2557,"navigation":2558,"path":64,"seo":2559,"stem":65,"__hash__":2560},"content/1.docs/7.cache.md",{"type":392,"value":393,"toc":2535,"icon":66},"minimark",[394,399,408,421,519,525,532,549,554,560,623,627,642,646,667,671,674,678,685,688,988,999,1052,1057,1334,1338,1341,1348,1415,1427,1528,1532,1551,1618,1624,1680,1693,1697,1704,1728,1738,1808,1814,1892,1895,1903,1907,1914,2052,2056,2061,2108,2112,2116,2135,2139,2147,2228,2233,2250,2255,2263,2267,2275,2331,2334,2426,2429,2454,2457,2505,2516,2525,2531],[395,396,398],"h2",{"id":397},"cached-handlers","Cached handlers",[400,401,402,403,407],"p",{},"To cache an event handler, you simply need to use the ",[404,405,406],"code",{},"defineCachedHandler"," method.",[400,409,410,411,414,415,420],{},"It works like ",[404,412,413],{},"defineHandler"," but with an second parameter for the ",[416,417,419],"a",{"href":418},"#options","cache options",".",[422,423,428],"pre",{"className":424,"code":425,"filename":426,"language":427,"meta":5,"style":5},"language-ts shiki shiki-themes github-light github-dark github-dark","import { defineCachedHandler } from \"nitro/cache\";\n\nexport default defineCachedHandler((event) => {\n  return \"I am cached for an hour\";\n}, { maxAge: 60 * 60 });\n","routes/cached.ts","ts",[404,429,430,453,460,489,500],{"__ignoreMap":5},[431,432,435,439,443,446,450],"span",{"class":433,"line":434},"line",1,[431,436,438],{"class":437},"so5gQ","import",[431,440,442],{"class":441},"slsVL"," { defineCachedHandler } ",[431,444,445],{"class":437},"from",[431,447,449],{"class":448},"sfrk1"," \"nitro/cache\"",[431,451,452],{"class":441},";\n",[431,454,456],{"class":433,"line":455},2,[431,457,459],{"emptyLinePlaceholder":458},true,"\n",[431,461,463,466,469,473,476,480,483,486],{"class":433,"line":462},3,[431,464,465],{"class":437},"export",[431,467,468],{"class":437}," default",[431,470,472],{"class":471},"shcOC"," defineCachedHandler",[431,474,475],{"class":441},"((",[431,477,479],{"class":478},"sQHwn","event",[431,481,482],{"class":441},") ",[431,484,485],{"class":437},"=>",[431,487,488],{"class":441}," {\n",[431,490,492,495,498],{"class":433,"line":491},4,[431,493,494],{"class":437},"  return",[431,496,497],{"class":448}," \"I am cached for an hour\"",[431,499,452],{"class":441},[431,501,503,506,510,513,516],{"class":433,"line":502},5,[431,504,505],{"class":441},"}, { maxAge: ",[431,507,509],{"class":508},"suiK_","60",[431,511,512],{"class":437}," *",[431,514,515],{"class":508}," 60",[431,517,518],{"class":441}," });\n",[400,520,521,522,420],{},"With this example, the response will be cached for 1 hour and a stale value will be sent to the client while the cache is being updated in the background. If you want to immediately return the updated response set ",[404,523,524],{},"swr: false",[400,526,527,528,531],{},"See the ",[416,529,530],{"href":418},"options"," section for more details about the available options.",[533,534,535],"important",{},[400,536,537,541,542,548],{},[538,539,540],"strong",{},"Request headers are dropped"," when handling cached responses. Use the ",[416,543,544,547],{"href":418},[404,545,546],{},"varies"," option"," to consider specific headers when caching and serving the responses.",[550,551,553],"h3",{"id":552},"automatic-http-headers","Automatic HTTP headers",[400,555,556,557,559],{},"When using ",[404,558,406],{},", Nitro automatically manages HTTP cache headers on cached responses:",[561,562,563,576,584],"ul",{},[564,565,566,571,572,575],"li",{},[538,567,568],{},[404,569,570],{},"etag"," -- A weak ETag (",[404,573,574],{},"W/\"...\"",") is generated from the response body hash if not already set by the handler.",[564,577,578,583],{},[538,579,580],{},[404,581,582],{},"last-modified"," -- Set to the current time when the response is first cached, if not already set.",[564,585,586,591,592,595,596,599,600,603,604],{},[538,587,588],{},[404,589,590],{},"cache-control"," -- Automatically set based on the ",[404,593,594],{},"swr",", ",[404,597,598],{},"maxAge",", and ",[404,601,602],{},"staleMaxAge"," options:\n",[561,605,606,616],{},[564,607,608,609,612,613],{},"With ",[404,610,611],{},"swr: true",": ",[404,614,615],{},"s-maxage=\u003CmaxAge>, stale-while-revalidate=\u003CstaleMaxAge>",[564,617,608,618,612,620],{},[404,619,524],{},[404,621,622],{},"max-age=\u003CmaxAge>",[550,624,626],{"id":625},"conditional-requests-304-not-modified","Conditional requests (304 Not Modified)",[400,628,629,630,633,634,637,638,641],{},"Cached handlers automatically support conditional requests. When a client sends ",[404,631,632],{},"if-none-match"," or ",[404,635,636],{},"if-modified-since"," headers matching the cached response, Nitro returns a ",[404,639,640],{},"304 Not Modified"," response without a body.",[550,643,645],{"id":644},"request-method-filtering","Request method filtering",[400,647,648,649,652,653,656,657,595,660,595,663,666],{},"Only ",[404,650,651],{},"GET"," and ",[404,654,655],{},"HEAD"," requests are cached. All other HTTP methods (",[404,658,659],{},"POST",[404,661,662],{},"PUT",[404,664,665],{},"DELETE",", etc.) automatically bypass the cache and call the handler directly.",[550,668,670],{"id":669},"request-deduplication","Request deduplication",[400,672,673],{},"When multiple concurrent requests hit the same cache key while the cache is being resolved, only one invocation of the handler runs. All concurrent requests wait for and share the same result.",[395,675,677],{"id":676},"cached-functions","Cached functions",[400,679,680,681,684],{},"You can also cache a function using the ",[404,682,683],{},"defineCachedFunction"," function. This is useful for caching the result of a function that is not an event handler, but is part of one, and reusing it in multiple handlers.",[400,686,687],{},"For example, you might want to cache the result of an API call for one hour:",[422,689,692],{"className":424,"code":690,"filename":691,"language":427,"meta":5,"style":5},"import { defineCachedFunction } from \"nitro/cache\";\nimport { defineHandler, type H3Event } from \"nitro\";\n\nexport default defineHandler(async (event) => {\n  const { repo } = event.context.params;\n  const stars = await cachedGHStars(repo).catch(() => 0)\n\n  return { repo, stars }\n});\n\nconst cachedGHStars = defineCachedFunction(async (repo: string) => {\n  const data = await fetch(`https://api.github.com/repos/${repo}`).then(res => res.json());\n\n  return data.stargazers_count;\n}, {\n  maxAge: 60 * 60,\n  name: \"ghStars\",\n  getKey: (repo: string) => repo\n});\n","routes/api/stars/[...repo].ts",[404,693,694,707,727,731,757,777,811,816,824,830,835,868,916,921,929,935,950,961,983],{"__ignoreMap":5},[431,695,696,698,701,703,705],{"class":433,"line":434},[431,697,438],{"class":437},[431,699,700],{"class":441}," { defineCachedFunction } ",[431,702,445],{"class":437},[431,704,449],{"class":448},[431,706,452],{"class":441},[431,708,709,711,714,717,720,722,725],{"class":433,"line":455},[431,710,438],{"class":437},[431,712,713],{"class":441}," { defineHandler, ",[431,715,716],{"class":437},"type",[431,718,719],{"class":441}," H3Event } ",[431,721,445],{"class":437},[431,723,724],{"class":448}," \"nitro\"",[431,726,452],{"class":441},[431,728,729],{"class":433,"line":462},[431,730,459],{"emptyLinePlaceholder":458},[431,732,733,735,737,740,743,746,749,751,753,755],{"class":433,"line":491},[431,734,465],{"class":437},[431,736,468],{"class":437},[431,738,739],{"class":471}," defineHandler",[431,741,742],{"class":441},"(",[431,744,745],{"class":437},"async",[431,747,748],{"class":441}," (",[431,750,479],{"class":478},[431,752,482],{"class":441},[431,754,485],{"class":437},[431,756,488],{"class":441},[431,758,759,762,765,768,771,774],{"class":433,"line":502},[431,760,761],{"class":437},"  const",[431,763,764],{"class":441}," { ",[431,766,767],{"class":508},"repo",[431,769,770],{"class":441}," } ",[431,772,773],{"class":437},"=",[431,775,776],{"class":441}," event.context.params;\n",[431,778,780,782,785,788,791,794,797,800,803,805,808],{"class":433,"line":779},6,[431,781,761],{"class":437},[431,783,784],{"class":508}," stars",[431,786,787],{"class":437}," =",[431,789,790],{"class":437}," await",[431,792,793],{"class":471}," cachedGHStars",[431,795,796],{"class":441},"(repo).",[431,798,799],{"class":471},"catch",[431,801,802],{"class":441},"(() ",[431,804,485],{"class":437},[431,806,807],{"class":508}," 0",[431,809,810],{"class":441},")\n",[431,812,814],{"class":433,"line":813},7,[431,815,459],{"emptyLinePlaceholder":458},[431,817,819,821],{"class":433,"line":818},8,[431,820,494],{"class":437},[431,822,823],{"class":441}," { repo, stars }\n",[431,825,827],{"class":433,"line":826},9,[431,828,829],{"class":441},"});\n",[431,831,833],{"class":433,"line":832},10,[431,834,459],{"emptyLinePlaceholder":458},[431,836,838,841,843,845,848,850,852,854,856,859,862,864,866],{"class":433,"line":837},11,[431,839,840],{"class":437},"const",[431,842,793],{"class":508},[431,844,787],{"class":437},[431,846,847],{"class":471}," defineCachedFunction",[431,849,742],{"class":441},[431,851,745],{"class":437},[431,853,748],{"class":441},[431,855,767],{"class":478},[431,857,858],{"class":437},":",[431,860,861],{"class":508}," string",[431,863,482],{"class":441},[431,865,485],{"class":437},[431,867,488],{"class":441},[431,869,871,873,876,878,880,883,885,888,890,893,896,899,901,904,907,910,913],{"class":433,"line":870},12,[431,872,761],{"class":437},[431,874,875],{"class":508}," data",[431,877,787],{"class":437},[431,879,790],{"class":437},[431,881,882],{"class":471}," fetch",[431,884,742],{"class":441},[431,886,887],{"class":448},"`https://api.github.com/repos/${",[431,889,767],{"class":441},[431,891,892],{"class":448},"}`",[431,894,895],{"class":441},").",[431,897,898],{"class":471},"then",[431,900,742],{"class":441},[431,902,903],{"class":478},"res",[431,905,906],{"class":437}," =>",[431,908,909],{"class":441}," res.",[431,911,912],{"class":471},"json",[431,914,915],{"class":441},"());\n",[431,917,919],{"class":433,"line":918},13,[431,920,459],{"emptyLinePlaceholder":458},[431,922,924,926],{"class":433,"line":923},14,[431,925,494],{"class":437},[431,927,928],{"class":441}," data.stargazers_count;\n",[431,930,932],{"class":433,"line":931},15,[431,933,934],{"class":441},"}, {\n",[431,936,938,941,943,945,947],{"class":433,"line":937},16,[431,939,940],{"class":441},"  maxAge: ",[431,942,509],{"class":508},[431,944,512],{"class":437},[431,946,515],{"class":508},[431,948,949],{"class":441},",\n",[431,951,953,956,959],{"class":433,"line":952},17,[431,954,955],{"class":441},"  name: ",[431,957,958],{"class":448},"\"ghStars\"",[431,960,949],{"class":441},[431,962,964,967,970,972,974,976,978,980],{"class":433,"line":963},18,[431,965,966],{"class":471},"  getKey",[431,968,969],{"class":441},": (",[431,971,767],{"class":478},[431,973,858],{"class":437},[431,975,861],{"class":508},[431,977,482],{"class":441},[431,979,485],{"class":437},[431,981,982],{"class":441}," repo\n",[431,984,986],{"class":433,"line":985},19,[431,987,829],{"class":441},[400,989,990,991,994,995,998],{},"The stars will be cached in development inside ",[404,992,993],{},".nitro/cache/functions/ghStars/\u003Cowner>/\u003Crepo>.json"," with ",[404,996,997],{},"value"," being the number of stars.",[422,1000,1003],{"className":1001,"code":1002,"language":912,"meta":5,"style":5},"language-json shiki shiki-themes github-light github-dark github-dark","{\"expires\":1677851092249,\"value\":43991,\"mtime\":1677847492540,\"integrity\":\"ZUHcsxCWEH\"}\n",[404,1004,1005],{"__ignoreMap":5},[431,1006,1007,1010,1013,1015,1018,1021,1024,1026,1029,1031,1034,1036,1039,1041,1044,1046,1049],{"class":433,"line":434},[431,1008,1009],{"class":441},"{",[431,1011,1012],{"class":508},"\"expires\"",[431,1014,858],{"class":441},[431,1016,1017],{"class":508},"1677851092249",[431,1019,1020],{"class":441},",",[431,1022,1023],{"class":508},"\"value\"",[431,1025,858],{"class":441},[431,1027,1028],{"class":508},"43991",[431,1030,1020],{"class":441},[431,1032,1033],{"class":508},"\"mtime\"",[431,1035,858],{"class":441},[431,1037,1038],{"class":508},"1677847492540",[431,1040,1020],{"class":441},[431,1042,1043],{"class":508},"\"integrity\"",[431,1045,858],{"class":441},[431,1047,1048],{"class":448},"\"ZUHcsxCWEH\"",[431,1050,1051],{"class":441},"}\n",[533,1053,1054],{},[400,1055,1056],{},"Because the cached data is serialized to JSON, it is important that the cached function does not return anything that cannot be serialized, such as Symbols, Maps, Sets...",[1058,1059,1060,1063],"callout",{},[400,1061,1062],{},"If you are using edge workers to host your application, you should follow the instructions below.",[1064,1065,1067,1074,1085,1331],"collapsible",{"name":1066},"Edge workers instructions",[400,1068,1069,1070,1073],{},"In edge workers, the instance is destroyed after each request. Nitro automatically uses ",[404,1071,1072],{},"event.waitUntil"," to keep the instance alive while the cache is being updated while the response is sent to the client.",[400,1075,1076,1077],{},"To ensure that your cached functions work as expected in edge workers, ",[538,1078,1079,1080,1082,1083,420],{},"you should always pass the ",[404,1081,479],{}," as the first argument to the function using ",[404,1084,683],{},[422,1086,1089],{"className":424,"code":1087,"filename":691,"highlights":1088,"language":427,"meta":5,"style":5},"import { defineCachedFunction } from \"nitro/cache\";\n\n\nexport default defineHandler(async (event) => {\n  const { repo } = event.context.params;\n  const stars = await cachedGHStars(event, repo).catch(() => 0)\n\n  return { repo, stars }\n});\n\nconst cachedGHStars = defineCachedFunction(async (event: H3Event, repo: string) => {\n  const data = await fetch(`https://api.github.com/repos/${repo}`).then(res => res.json());\n\n  return data.stargazers_count;\n}, {\n  maxAge: 60 * 60,\n  name: \"ghStars\",\n  getKey: (event: H3Event, repo: string) => repo\n});\n",[502,832,952],[404,1090,1091,1103,1107,1111,1133,1149,1174,1178,1184,1188,1193,1230,1266,1270,1276,1280,1292,1301,1327],{"__ignoreMap":5},[431,1092,1093,1095,1097,1099,1101],{"class":433,"line":434},[431,1094,438],{"class":437},[431,1096,700],{"class":441},[431,1098,445],{"class":437},[431,1100,449],{"class":448},[431,1102,452],{"class":441},[431,1104,1105],{"class":433,"line":455},[431,1106,459],{"emptyLinePlaceholder":458},[431,1108,1109],{"class":433,"line":462},[431,1110,459],{"emptyLinePlaceholder":458},[431,1112,1113,1115,1117,1119,1121,1123,1125,1127,1129,1131],{"class":433,"line":491},[431,1114,465],{"class":437},[431,1116,468],{"class":437},[431,1118,739],{"class":471},[431,1120,742],{"class":441},[431,1122,745],{"class":437},[431,1124,748],{"class":441},[431,1126,479],{"class":478},[431,1128,482],{"class":441},[431,1130,485],{"class":437},[431,1132,488],{"class":441},[431,1134,1137,1139,1141,1143,1145,1147],{"class":1135,"line":502},[433,1136],"highlight",[431,1138,761],{"class":437},[431,1140,764],{"class":441},[431,1142,767],{"class":508},[431,1144,770],{"class":441},[431,1146,773],{"class":437},[431,1148,776],{"class":441},[431,1150,1151,1153,1155,1157,1159,1161,1164,1166,1168,1170,1172],{"class":433,"line":779},[431,1152,761],{"class":437},[431,1154,784],{"class":508},[431,1156,787],{"class":437},[431,1158,790],{"class":437},[431,1160,793],{"class":471},[431,1162,1163],{"class":441},"(event, repo).",[431,1165,799],{"class":471},[431,1167,802],{"class":441},[431,1169,485],{"class":437},[431,1171,807],{"class":508},[431,1173,810],{"class":441},[431,1175,1176],{"class":433,"line":813},[431,1177,459],{"emptyLinePlaceholder":458},[431,1179,1180,1182],{"class":433,"line":818},[431,1181,494],{"class":437},[431,1183,823],{"class":441},[431,1185,1186],{"class":433,"line":826},[431,1187,829],{"class":441},[431,1189,1191],{"class":1190,"line":832},[433,1136],[431,1192,459],{"emptyLinePlaceholder":458},[431,1194,1195,1197,1199,1201,1203,1205,1207,1209,1211,1213,1216,1218,1220,1222,1224,1226,1228],{"class":433,"line":837},[431,1196,840],{"class":437},[431,1198,793],{"class":508},[431,1200,787],{"class":437},[431,1202,847],{"class":471},[431,1204,742],{"class":441},[431,1206,745],{"class":437},[431,1208,748],{"class":441},[431,1210,479],{"class":478},[431,1212,858],{"class":437},[431,1214,1215],{"class":471}," H3Event",[431,1217,595],{"class":441},[431,1219,767],{"class":478},[431,1221,858],{"class":437},[431,1223,861],{"class":508},[431,1225,482],{"class":441},[431,1227,485],{"class":437},[431,1229,488],{"class":441},[431,1231,1232,1234,1236,1238,1240,1242,1244,1246,1248,1250,1252,1254,1256,1258,1260,1262,1264],{"class":433,"line":870},[431,1233,761],{"class":437},[431,1235,875],{"class":508},[431,1237,787],{"class":437},[431,1239,790],{"class":437},[431,1241,882],{"class":471},[431,1243,742],{"class":441},[431,1245,887],{"class":448},[431,1247,767],{"class":441},[431,1249,892],{"class":448},[431,1251,895],{"class":441},[431,1253,898],{"class":471},[431,1255,742],{"class":441},[431,1257,903],{"class":478},[431,1259,906],{"class":437},[431,1261,909],{"class":441},[431,1263,912],{"class":471},[431,1265,915],{"class":441},[431,1267,1268],{"class":433,"line":918},[431,1269,459],{"emptyLinePlaceholder":458},[431,1271,1272,1274],{"class":433,"line":923},[431,1273,494],{"class":437},[431,1275,928],{"class":441},[431,1277,1278],{"class":433,"line":931},[431,1279,934],{"class":441},[431,1281,1282,1284,1286,1288,1290],{"class":433,"line":937},[431,1283,940],{"class":441},[431,1285,509],{"class":508},[431,1287,512],{"class":437},[431,1289,515],{"class":508},[431,1291,949],{"class":441},[431,1293,1295,1297,1299],{"class":1294,"line":952},[433,1136],[431,1296,955],{"class":441},[431,1298,958],{"class":448},[431,1300,949],{"class":441},[431,1302,1303,1305,1307,1309,1311,1313,1315,1317,1319,1321,1323,1325],{"class":433,"line":963},[431,1304,966],{"class":471},[431,1306,969],{"class":441},[431,1308,479],{"class":478},[431,1310,858],{"class":437},[431,1312,1215],{"class":471},[431,1314,595],{"class":441},[431,1316,767],{"class":478},[431,1318,858],{"class":437},[431,1320,861],{"class":508},[431,1322,482],{"class":441},[431,1324,485],{"class":437},[431,1326,982],{"class":441},[431,1328,1329],{"class":433,"line":985},[431,1330,829],{"class":441},[400,1332,1333],{},"This way, the function will be able to keep the instance alive while the cache is being updated without slowing down the response to the client.",[395,1335,1337],{"id":1336},"using-route-rules","Using route rules",[400,1339,1340],{},"This feature enables you to add caching routes based on a glob pattern directly in the main configuration file. This is especially useful to have a global cache strategy for a part of your application.",[400,1342,1343,1344,1347],{},"Cache all the blog routes for 1 hour with ",[404,1345,1346],{},"stale-while-revalidate"," behavior:",[422,1349,1352],{"className":424,"code":1350,"filename":1351,"language":427,"meta":5,"style":5},"import { defineNitroConfig } from \"nitro/config\";\n\nexport default defineNitroConfig({\n  routeRules: {\n    \"/blog/**\": { cache: { maxAge: 60 * 60 } },\n  },\n});\n","nitro.config.ts",[404,1353,1354,1368,1372,1384,1389,1406,1411],{"__ignoreMap":5},[431,1355,1356,1358,1361,1363,1366],{"class":433,"line":434},[431,1357,438],{"class":437},[431,1359,1360],{"class":441}," { defineNitroConfig } ",[431,1362,445],{"class":437},[431,1364,1365],{"class":448}," \"nitro/config\"",[431,1367,452],{"class":441},[431,1369,1370],{"class":433,"line":455},[431,1371,459],{"emptyLinePlaceholder":458},[431,1373,1374,1376,1378,1381],{"class":433,"line":462},[431,1375,465],{"class":437},[431,1377,468],{"class":437},[431,1379,1380],{"class":471}," defineNitroConfig",[431,1382,1383],{"class":441},"({\n",[431,1385,1386],{"class":433,"line":491},[431,1387,1388],{"class":441},"  routeRules: {\n",[431,1390,1391,1394,1397,1399,1401,1403],{"class":433,"line":502},[431,1392,1393],{"class":448},"    \"/blog/**\"",[431,1395,1396],{"class":441},": { cache: { maxAge: ",[431,1398,509],{"class":508},[431,1400,512],{"class":437},[431,1402,515],{"class":508},[431,1404,1405],{"class":441}," } },\n",[431,1407,1408],{"class":433,"line":779},[431,1409,1410],{"class":441},"  },\n",[431,1412,1413],{"class":433,"line":813},[431,1414,829],{"class":441},[400,1416,1417,1418,1422,1423,1426],{},"If we want to use a ",[416,1419,1421],{"href":1420},"#cache-storage","custom cache storage"," mount point, we can use the ",[404,1424,1425],{},"base"," option.",[422,1428,1430],{"className":424,"code":1429,"filename":1351,"language":427,"meta":5,"style":5},"import { defineNitroConfig } from \"nitro/config\";\n\nexport default defineNitroConfig({\n  storage: {\n    redis: {\n      driver: \"redis\",\n      url: \"redis://localhost:6379\",\n    },\n  },\n  routeRules: {\n    \"/blog/**\": { cache: { maxAge: 60 * 60, base: \"redis\" } },\n  },\n});\n",[404,1431,1432,1444,1448,1458,1463,1468,1478,1488,1493,1497,1501,1520,1524],{"__ignoreMap":5},[431,1433,1434,1436,1438,1440,1442],{"class":433,"line":434},[431,1435,438],{"class":437},[431,1437,1360],{"class":441},[431,1439,445],{"class":437},[431,1441,1365],{"class":448},[431,1443,452],{"class":441},[431,1445,1446],{"class":433,"line":455},[431,1447,459],{"emptyLinePlaceholder":458},[431,1449,1450,1452,1454,1456],{"class":433,"line":462},[431,1451,465],{"class":437},[431,1453,468],{"class":437},[431,1455,1380],{"class":471},[431,1457,1383],{"class":441},[431,1459,1460],{"class":433,"line":491},[431,1461,1462],{"class":441},"  storage: {\n",[431,1464,1465],{"class":433,"line":502},[431,1466,1467],{"class":441},"    redis: {\n",[431,1469,1470,1473,1476],{"class":433,"line":779},[431,1471,1472],{"class":441},"      driver: ",[431,1474,1475],{"class":448},"\"redis\"",[431,1477,949],{"class":441},[431,1479,1480,1483,1486],{"class":433,"line":813},[431,1481,1482],{"class":441},"      url: ",[431,1484,1485],{"class":448},"\"redis://localhost:6379\"",[431,1487,949],{"class":441},[431,1489,1490],{"class":433,"line":818},[431,1491,1492],{"class":441},"    },\n",[431,1494,1495],{"class":433,"line":826},[431,1496,1410],{"class":441},[431,1498,1499],{"class":433,"line":832},[431,1500,1388],{"class":441},[431,1502,1503,1505,1507,1509,1511,1513,1516,1518],{"class":433,"line":837},[431,1504,1393],{"class":448},[431,1506,1396],{"class":441},[431,1508,509],{"class":508},[431,1510,512],{"class":437},[431,1512,515],{"class":508},[431,1514,1515],{"class":441},", base: ",[431,1517,1475],{"class":448},[431,1519,1405],{"class":441},[431,1521,1522],{"class":433,"line":870},[431,1523,1410],{"class":441},[431,1525,1526],{"class":433,"line":918},[431,1527,829],{"class":441},[550,1529,1531],{"id":1530},"route-rules-shortcuts","Route rules shortcuts",[400,1533,1534,1535,1537,1538,1540,1541,1544,1545,1547,1548,1550],{},"You can use the ",[404,1536,594],{}," shortcut for enabling ",[404,1539,1346],{}," caching on route rules. When set to ",[404,1542,1543],{},"true",", SWR is enabled with the default ",[404,1546,598],{},". When set to a number, it is used as the ",[404,1549,598],{}," value in seconds.",[422,1552,1554],{"className":424,"code":1553,"filename":1351,"language":427,"meta":5,"style":5},"import { defineNitroConfig } from \"nitro/config\";\n\nexport default defineNitroConfig({\n  routeRules: {\n    \"/blog/**\": { swr: true },\n    \"/api/**\": { swr: 3600 },\n  },\n});\n",[404,1555,1556,1568,1572,1582,1586,1598,1610,1614],{"__ignoreMap":5},[431,1557,1558,1560,1562,1564,1566],{"class":433,"line":434},[431,1559,438],{"class":437},[431,1561,1360],{"class":441},[431,1563,445],{"class":437},[431,1565,1365],{"class":448},[431,1567,452],{"class":441},[431,1569,1570],{"class":433,"line":455},[431,1571,459],{"emptyLinePlaceholder":458},[431,1573,1574,1576,1578,1580],{"class":433,"line":462},[431,1575,465],{"class":437},[431,1577,468],{"class":437},[431,1579,1380],{"class":471},[431,1581,1383],{"class":441},[431,1583,1584],{"class":433,"line":491},[431,1585,1388],{"class":441},[431,1587,1588,1590,1593,1595],{"class":433,"line":502},[431,1589,1393],{"class":448},[431,1591,1592],{"class":441},": { swr: ",[431,1594,1543],{"class":508},[431,1596,1597],{"class":441}," },\n",[431,1599,1600,1603,1605,1608],{"class":433,"line":779},[431,1601,1602],{"class":448},"    \"/api/**\"",[431,1604,1592],{"class":441},[431,1606,1607],{"class":508},"3600",[431,1609,1597],{"class":441},[431,1611,1612],{"class":433,"line":813},[431,1613,1410],{"class":441},[431,1615,1616],{"class":433,"line":818},[431,1617,829],{"class":441},[400,1619,1620,1621,858],{},"To explicitly disable caching on a route, set ",[404,1622,1623],{},"cache: false",[422,1625,1627],{"className":424,"code":1626,"filename":1351,"language":427,"meta":5,"style":5},"import { defineNitroConfig } from \"nitro/config\";\n\nexport default defineNitroConfig({\n  routeRules: {\n    \"/api/realtime/**\": { cache: false },\n  },\n});\n",[404,1628,1629,1641,1645,1655,1659,1672,1676],{"__ignoreMap":5},[431,1630,1631,1633,1635,1637,1639],{"class":433,"line":434},[431,1632,438],{"class":437},[431,1634,1360],{"class":441},[431,1636,445],{"class":437},[431,1638,1365],{"class":448},[431,1640,452],{"class":441},[431,1642,1643],{"class":433,"line":455},[431,1644,459],{"emptyLinePlaceholder":458},[431,1646,1647,1649,1651,1653],{"class":433,"line":462},[431,1648,465],{"class":437},[431,1650,468],{"class":437},[431,1652,1380],{"class":471},[431,1654,1383],{"class":441},[431,1656,1657],{"class":433,"line":491},[431,1658,1388],{"class":441},[431,1660,1661,1664,1667,1670],{"class":433,"line":502},[431,1662,1663],{"class":448},"    \"/api/realtime/**\"",[431,1665,1666],{"class":441},": { cache: ",[431,1668,1669],{"class":508},"false",[431,1671,1597],{"class":441},[431,1673,1674],{"class":433,"line":779},[431,1675,1410],{"class":441},[431,1677,1678],{"class":433,"line":813},[431,1679,829],{"class":441},[1681,1682,1683],"note",{},[400,1684,1685,1686,1689,1690,420],{},"When using route rules, cached handlers use the group ",[404,1687,1688],{},"'nitro/route-rules'"," instead of the default ",[404,1691,1692],{},"'nitro/handlers'",[395,1694,1696],{"id":1695},"cache-storage","Cache storage",[400,1698,1699,1700,1703],{},"Nitro stores the data in the ",[404,1701,1702],{},"cache"," storage mount point.",[561,1705,1706,1716],{},[564,1707,1708,1709,1715],{},"In production, it will use the ",[416,1710,1714],{"href":1711,"rel":1712},"https://unstorage.unjs.io/drivers/memory",[1713],"nofollow","memory driver"," by default.",[564,1717,1718,1719,1724,1725,895],{},"In development, it will use the ",[416,1720,1723],{"href":1721,"rel":1722},"https://unstorage.unjs.io/drivers/fs",[1713],"filesystem driver",", writing to a temporary dir (",[404,1726,1727],{},".nitro/cache",[400,1729,1730,1731,1733,1734,1737],{},"To overwrite the production storage, set the ",[404,1732,1702],{}," mount point using the ",[404,1735,1736],{},"storage"," option:",[422,1739,1741],{"className":424,"code":1740,"filename":1351,"language":427,"meta":5,"style":5},"import { defineNitroConfig } from \"nitro/config\";\n\nexport default defineNitroConfig({\n  storage: {\n    cache: {\n      driver: 'redis',\n      /* redis connector options */\n    }\n  }\n})\n",[404,1742,1743,1755,1759,1769,1773,1778,1787,1793,1798,1803],{"__ignoreMap":5},[431,1744,1745,1747,1749,1751,1753],{"class":433,"line":434},[431,1746,438],{"class":437},[431,1748,1360],{"class":441},[431,1750,445],{"class":437},[431,1752,1365],{"class":448},[431,1754,452],{"class":441},[431,1756,1757],{"class":433,"line":455},[431,1758,459],{"emptyLinePlaceholder":458},[431,1760,1761,1763,1765,1767],{"class":433,"line":462},[431,1762,465],{"class":437},[431,1764,468],{"class":437},[431,1766,1380],{"class":471},[431,1768,1383],{"class":441},[431,1770,1771],{"class":433,"line":491},[431,1772,1462],{"class":441},[431,1774,1775],{"class":433,"line":502},[431,1776,1777],{"class":441},"    cache: {\n",[431,1779,1780,1782,1785],{"class":433,"line":779},[431,1781,1472],{"class":441},[431,1783,1784],{"class":448},"'redis'",[431,1786,949],{"class":441},[431,1788,1789],{"class":433,"line":813},[431,1790,1792],{"class":1791},"sCsY4","      /* redis connector options */\n",[431,1794,1795],{"class":433,"line":818},[431,1796,1797],{"class":441},"    }\n",[431,1799,1800],{"class":433,"line":826},[431,1801,1802],{"class":441},"  }\n",[431,1804,1805],{"class":433,"line":832},[431,1806,1807],{"class":441},"})\n",[400,1809,1810,1811,1737],{},"In development, you can also overwrite the cache mount point using the ",[404,1812,1813],{},"devStorage",[422,1815,1817],{"className":424,"code":1816,"filename":1351,"language":427,"meta":5,"style":5},"import { defineNitroConfig } from \"nitro/config\";\n\nexport default defineNitroConfig({\n  storage: {\n    cache: {\n      // production cache storage\n    },\n  },\n  devStorage: {\n    cache: {\n      // development cache storage\n    }\n  }\n})\n",[404,1818,1819,1831,1835,1845,1849,1853,1858,1862,1866,1871,1875,1880,1884,1888],{"__ignoreMap":5},[431,1820,1821,1823,1825,1827,1829],{"class":433,"line":434},[431,1822,438],{"class":437},[431,1824,1360],{"class":441},[431,1826,445],{"class":437},[431,1828,1365],{"class":448},[431,1830,452],{"class":441},[431,1832,1833],{"class":433,"line":455},[431,1834,459],{"emptyLinePlaceholder":458},[431,1836,1837,1839,1841,1843],{"class":433,"line":462},[431,1838,465],{"class":437},[431,1840,468],{"class":437},[431,1842,1380],{"class":471},[431,1844,1383],{"class":441},[431,1846,1847],{"class":433,"line":491},[431,1848,1462],{"class":441},[431,1850,1851],{"class":433,"line":502},[431,1852,1777],{"class":441},[431,1854,1855],{"class":433,"line":779},[431,1856,1857],{"class":1791},"      // production cache storage\n",[431,1859,1860],{"class":433,"line":813},[431,1861,1492],{"class":441},[431,1863,1864],{"class":433,"line":818},[431,1865,1410],{"class":441},[431,1867,1868],{"class":433,"line":826},[431,1869,1870],{"class":441},"  devStorage: {\n",[431,1872,1873],{"class":433,"line":832},[431,1874,1777],{"class":441},[431,1876,1877],{"class":433,"line":837},[431,1878,1879],{"class":1791},"      // development cache storage\n",[431,1881,1882],{"class":433,"line":870},[431,1883,1797],{"class":441},[431,1885,1886],{"class":433,"line":918},[431,1887,1802],{"class":441},[431,1889,1890],{"class":433,"line":923},[431,1891,1807],{"class":441},[395,1893,1894],{"id":530},"Options",[400,1896,1897,1898,652,1900,1902],{},"The ",[404,1899,406],{},[404,1901,683],{}," functions accept the following options:",[550,1904,1906],{"id":1905},"shared-options","Shared options",[400,1908,1909,1910,652,1912,858],{},"These options are available for both ",[404,1911,406],{},[404,1913,683],{},[1915,1916,1917,1930,1940,1953,1967,1980,1992,2008,2024,2034,2042],"field-group",{},[1918,1919,1921],"field",{"name":1425,"type":1920},"string",[400,1922,1923,1924,1927,1928,420],{},"Name of the storage mountpoint to use for caching. ",[1925,1926],"br",{},"\nDefault to ",[404,1929,1702],{},[1918,1931,1933],{"name":1932,"type":1920},"name",[400,1934,1935,1936,1939],{},"Guessed from function name if not provided, and falls back to ",[404,1937,1938],{},"'_'"," otherwise.",[1918,1941,1943],{"name":1942,"type":1920},"group",[400,1944,1945,1946,1948,1949,1952],{},"Defaults to ",[404,1947,1692],{}," for handlers and ",[404,1950,1951],{},"'nitro/functions'"," for functions.",[1918,1954,1957],{"name":1955,"type":1956},"getKey()","(...args) => string",[400,1958,1959,1960,1963,1964,1966],{},"A function that accepts the same arguments as the original function and returns a cache key (",[404,1961,1962],{},"String","). ",[1925,1965],{},"\nIf not provided, a built-in hash function will be used to generate a key based on the function arguments. For cached handlers, the key is derived from the request URL path and search params.",[1918,1968,1970],{"name":1969,"type":1920},"integrity",[400,1971,1972,1973,1975,1976,1979],{},"A value that invalidates the cache when changed. ",[1925,1974],{},"\nBy default, it is computed from ",[538,1977,1978],{},"function code",", used in development to invalidate the cache when the function code changes.",[1918,1981,1983],{"name":598,"type":1982},"number",[400,1984,1985,1986,1927,1988,1991],{},"Maximum age that cache is valid, in seconds. ",[1925,1987],{},[404,1989,1990],{},"1"," (second).",[1918,1993,1994],{"name":602,"type":1982},[400,1995,1996,1997,2000,2001,2003,2004,2007],{},"Maximum age that a stale cache is valid, in seconds. If set to ",[404,1998,1999],{},"-1"," a stale value will still be sent to the client while the cache updates in the background. ",[1925,2002],{},"\nDefaults to ",[404,2005,2006],{},"0"," (disabled).",[1918,2009,2011],{"name":594,"type":2010},"boolean",[400,2012,2013,2014,2016,2017,2019,2020,2003,2022,420],{},"Enable ",[404,2015,1346],{}," behavior to serve a stale cached response while asynchronously revalidating it. ",[1925,2018],{},"\nWhen enabled, stale cached values are returned immediately while revalidation happens in the background. When disabled, the caller waits for the fresh value before responding (the stale entry is cleared). ",[1925,2021],{},[404,2023,1543],{},[1918,2025,2028],{"name":2026,"type":2027},"shouldInvalidateCache()","(...args) => boolean | Promise\u003Cboolean>",[400,2029,2030,2031,2033],{},"A function that returns a ",[404,2032,2010],{}," to invalidate the current cache and create a new one.",[1918,2035,2037],{"name":2036,"type":2027},"shouldBypassCache()",[400,2038,2030,2039,2041],{},[404,2040,2010],{}," to bypass the current cache without invalidating the existing entry.",[1918,2043,2046],{"name":2044,"type":2045},"onError()","(error: unknown) => void",[400,2047,2048,2049,2051],{},"A custom error handler called when the cached function throws. ",[1925,2050],{},"\nBy default, errors are logged to the console and captured by the Nitro error handler.",[550,2053,2055],{"id":2054},"handler-only-options","Handler-only options",[400,2057,2058,2059,858],{},"These options are only available for ",[404,2060,406],{},[1915,2062,2063,2080],{},[1918,2064,2066],{"name":2065,"type":2010},"headersOnly",[400,2067,2068,2069,2071,2072,595,2074,2076,2077,2079],{},"When ",[404,2070,1543],{},", skip full response caching and only handle conditional request headers (",[404,2073,632],{},[404,2075,636],{},") for ",[404,2078,640],{}," responses. The handler is called on every request but benefits from conditional caching.",[1918,2081,2083],{"name":546,"type":2082},"string[]",[400,2084,2085,2086,2088,2089,2091,2092,2095,2096,2098,2099,2088,2101,2103,2104,2107],{},"An array of request header names to vary the cache key on. Headers listed here are preserved on the request during cache resolution and included in the cache key, making the cache unique per combination of header values. ",[1925,2087],{}," ",[1925,2090],{},"\nHeaders ",[538,2093,2094],{},"not"," listed in ",[404,2097,546],{}," are stripped from the request before calling the handler to ensure consistent cache hits. ",[1925,2100],{},[1925,2102],{},"\nFor multi-tenant environments, you may want to pass ",[404,2105,2106],{},"['host', 'x-forwarded-host']"," to ensure these headers are not discarded and that the cache is unique per tenant.",[550,2109,2111],{"id":2110},"function-only-options","Function-only options",[400,2113,2058,2114,858],{},[404,2115,683],{},[1915,2117,2118,2125],{},[1918,2119,2122],{"name":2120,"type":2121},"transform()","(entry: CacheEntry, ...args) => any",[400,2123,2124],{},"Transform the cache entry before returning. The return value replaces the cached value.",[1918,2126,2129],{"name":2127,"type":2128},"validate()","(entry: CacheEntry, ...args) => boolean",[400,2130,2131,2132,2134],{},"Validate a cache entry. Return ",[404,2133,1669],{}," to treat the entry as invalid and trigger re-resolution.",[395,2136,2138],{"id":2137},"swr-behavior","SWR behavior",[400,2140,1897,2141,2143,2144,2146],{},[404,2142,1346],{}," (SWR) pattern is enabled by default (",[404,2145,611],{},"). Understanding how it interacts with other options:",[2148,2149,2150,2168],"table",{},[2151,2152,2153],"thead",{},[2154,2155,2156,2161,2165],"tr",{},[2157,2158,2159],"th",{},[404,2160,594],{},[2157,2162,2163],{},[404,2164,598],{},[2157,2166,2167],{},"Behavior",[2169,2170,2171,2186,2199,2212],"tbody",{},[2154,2172,2173,2179,2183],{},[2174,2175,2176,2178],"td",{},[404,2177,1543],{}," (default)",[2174,2180,2181,2178],{},[404,2182,1990],{},[2174,2184,2185],{},"Cache for 1 second, serve stale while revalidating",[2154,2187,2188,2192,2196],{},[2174,2189,2190],{},[404,2191,1543],{},[2174,2193,2194],{},[404,2195,1607],{},[2174,2197,2198],{},"Cache for 1 hour, serve stale while revalidating",[2154,2200,2201,2205,2209],{},[2174,2202,2203],{},[404,2204,1669],{},[2174,2206,2207],{},[404,2208,1607],{},[2174,2210,2211],{},"Cache for 1 hour, wait for fresh value when expired",[2154,2213,2214,2218,2225],{},[2174,2215,2216],{},[404,2217,1543],{},[2174,2219,2220,994,2222],{},[404,2221,1607],{},[404,2223,2224],{},"staleMaxAge: 600",[2174,2226,2227],{},"Cache for 1 hour, serve stale for up to 10 minutes while revalidating",[400,2229,2068,2230,2232],{},[404,2231,594],{}," is enabled and a cached value exists but has expired:",[2234,2235,2237,2241,2244],"steps",{"level":2236},"4",[2238,2239,2240],"h4",{},"The stale cached value is returned immediately to the client.",[2238,2242,2243],{},"The function/handler is called in the background to refresh the cache.",[2238,2245,2246,2247,2249],{},"On edge workers, ",[404,2248,1072],{}," is used to keep the background refresh alive.",[400,2251,2068,2252,2254],{},[404,2253,594],{}," is disabled and a cached value has expired:",[2234,2256,2257,2260],{"level":2236},[2238,2258,2259],{},"The stale entry is cleared.",[2238,2261,2262],{},"The client waits for the function/handler to resolve with a fresh value.",[395,2264,2266],{"id":2265},"cache-keys-and-invalidation","Cache keys and invalidation",[400,2268,2269,2270,633,2272,2274],{},"When using the ",[404,2271,683],{},[404,2273,406],{}," functions, the cache key is generated using the following pattern:",[422,2276,2278],{"className":424,"code":2277,"language":427,"meta":5,"style":5},"`${options.base}:${options.group}:${options.name}:${options.getKey(...args)}.json`\n",[404,2279,2280],{"__ignoreMap":5},[431,2281,2282,2285,2287,2289,2291,2294,2296,2298,2300,2302,2304,2306,2308,2310,2312,2314,2317,2319,2322,2325,2328],{"class":433,"line":434},[431,2283,2284],{"class":448},"`${",[431,2286,530],{"class":441},[431,2288,420],{"class":448},[431,2290,1425],{"class":441},[431,2292,2293],{"class":448},"}:${",[431,2295,530],{"class":441},[431,2297,420],{"class":448},[431,2299,1942],{"class":441},[431,2301,2293],{"class":448},[431,2303,530],{"class":441},[431,2305,420],{"class":448},[431,2307,1932],{"class":441},[431,2309,2293],{"class":448},[431,2311,530],{"class":441},[431,2313,420],{"class":448},[431,2315,2316],{"class":471},"getKey",[431,2318,742],{"class":448},[431,2320,2321],{"class":437},"...",[431,2323,2324],{"class":441},"args",[431,2326,2327],{"class":448},")",[431,2329,2330],{"class":448},"}.json`\n",[400,2332,2333],{},"For example, the following function:",[422,2335,2337],{"className":424,"code":2336,"language":427,"meta":5,"style":5},"import { defineCachedFunction } from \"nitro/cache\";\n\nconst getAccessToken = defineCachedFunction(() => {\n  return String(Date.now())\n}, {\n  maxAge: 10,\n  name: \"getAccessToken\",\n  getKey: () => \"default\"\n});\n",[404,2338,2339,2351,2355,2372,2388,2392,2401,2410,2422],{"__ignoreMap":5},[431,2340,2341,2343,2345,2347,2349],{"class":433,"line":434},[431,2342,438],{"class":437},[431,2344,700],{"class":441},[431,2346,445],{"class":437},[431,2348,449],{"class":448},[431,2350,452],{"class":441},[431,2352,2353],{"class":433,"line":455},[431,2354,459],{"emptyLinePlaceholder":458},[431,2356,2357,2359,2362,2364,2366,2368,2370],{"class":433,"line":462},[431,2358,840],{"class":437},[431,2360,2361],{"class":508}," getAccessToken",[431,2363,787],{"class":437},[431,2365,847],{"class":471},[431,2367,802],{"class":441},[431,2369,485],{"class":437},[431,2371,488],{"class":441},[431,2373,2374,2376,2379,2382,2385],{"class":433,"line":491},[431,2375,494],{"class":437},[431,2377,2378],{"class":471}," String",[431,2380,2381],{"class":441},"(Date.",[431,2383,2384],{"class":471},"now",[431,2386,2387],{"class":441},"())\n",[431,2389,2390],{"class":433,"line":502},[431,2391,934],{"class":441},[431,2393,2394,2396,2399],{"class":433,"line":779},[431,2395,940],{"class":441},[431,2397,2398],{"class":508},"10",[431,2400,949],{"class":441},[431,2402,2403,2405,2408],{"class":433,"line":813},[431,2404,955],{"class":441},[431,2406,2407],{"class":448},"\"getAccessToken\"",[431,2409,949],{"class":441},[431,2411,2412,2414,2417,2419],{"class":433,"line":818},[431,2413,966],{"class":471},[431,2415,2416],{"class":441},": () ",[431,2418,485],{"class":437},[431,2420,2421],{"class":448}," \"default\"\n",[431,2423,2424],{"class":433,"line":826},[431,2425,829],{"class":441},[400,2427,2428],{},"Will generate the following cache key:",[422,2430,2432],{"className":424,"code":2431,"language":427,"meta":5,"style":5},"cache:nitro/functions:getAccessToken:default.json\n",[404,2433,2434],{"__ignoreMap":5},[431,2435,2436,2438,2441,2443,2446,2448,2451],{"class":433,"line":434},[431,2437,1702],{"class":471},[431,2439,2440],{"class":441},":nitro",[431,2442,387],{"class":437},[431,2444,2445],{"class":471},"functions",[431,2447,858],{"class":441},[431,2449,2450],{"class":471},"getAccessToken",[431,2452,2453],{"class":441},":default.json\n",[400,2455,2456],{},"You can invalidate the cached function entry with:",[422,2458,2460],{"className":424,"code":2459,"language":427,"meta":5,"style":5},"import { useStorage } from \"nitro/storage\";\n\nawait useStorage('cache').removeItem('nitro/functions:getAccessToken:default.json')\n",[404,2461,2462,2476,2480],{"__ignoreMap":5},[431,2463,2464,2466,2469,2471,2474],{"class":433,"line":434},[431,2465,438],{"class":437},[431,2467,2468],{"class":441}," { useStorage } ",[431,2470,445],{"class":437},[431,2472,2473],{"class":448}," \"nitro/storage\"",[431,2475,452],{"class":441},[431,2477,2478],{"class":433,"line":455},[431,2479,459],{"emptyLinePlaceholder":458},[431,2481,2482,2485,2488,2490,2493,2495,2498,2500,2503],{"class":433,"line":462},[431,2483,2484],{"class":437},"await",[431,2486,2487],{"class":471}," useStorage",[431,2489,742],{"class":441},[431,2491,2492],{"class":448},"'cache'",[431,2494,895],{"class":441},[431,2496,2497],{"class":471},"removeItem",[431,2499,742],{"class":441},[431,2501,2502],{"class":448},"'nitro/functions:getAccessToken:default.json'",[431,2504,810],{"class":441},[1681,2506,2507],{},[400,2508,2509,2510,2515],{},"For cached handlers, the cache key includes a hash of the URL path and, when using the ",[416,2511,2513],{"href":2512},"#handler-only-options",[404,2514,546],{}," option, hashes of the specified header values appended to the key.",[1681,2517,2518],{},[400,2519,2520,2521,2524],{},"Responses with HTTP status codes ",[404,2522,2523],{},">= 400"," or with an undefined body are not cached. This prevents caching error responses.",[2526,2527,2528],"read-more",{"to":69},[400,2529,2530],{},"Read more about the Nitro storage.",[2532,2533,2534],"style",{},"html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":5,"searchDepth":455,"depth":455,"links":2536},[2537,2543,2544,2547,2548,2553,2554],{"id":397,"depth":455,"text":398,"children":2538},[2539,2540,2541,2542],{"id":552,"depth":462,"text":553},{"id":625,"depth":462,"text":626},{"id":644,"depth":462,"text":645},{"id":669,"depth":462,"text":670},{"id":676,"depth":455,"text":677},{"id":1336,"depth":455,"text":1337,"children":2545},[2546],{"id":1530,"depth":462,"text":1531},{"id":1695,"depth":455,"text":1696},{"id":530,"depth":455,"text":1894,"children":2549},[2550,2551,2552],{"id":1905,"depth":462,"text":1906},{"id":2054,"depth":462,"text":2055},{"id":2110,"depth":462,"text":2111},{"id":2137,"depth":455,"text":2138},{"id":2265,"depth":455,"text":2266},"Nitro provides a caching system built on top of the storage layer, powered by ocache.","md",{"icon":66},{"icon":66},{"title":63,"description":2555},"QstNUnsjbJ57d0GAwI4Jmr3mmS5bxR7HGkvg49NN7Ds",[2562,2564],{"title":58,"path":59,"stem":60,"description":2563,"icon":61,"children":-1},"Use a server entry to create a global middleware that runs for all routes before they are matched.",{"title":68,"path":69,"stem":70,"description":2565,"icon":71,"children":-1},"Nitro provides a built-in storage layer that can abstract filesystem or database or any other data source.",1775151184714]