[{"data":1,"prerenderedAt":1871},["ShallowReactive",2],{"navigation":3,"-docs-cache":228,"-docs-cache-surround":1866},[4,83,212,218,225],{"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],{"title":219,"path":220,"stem":221,"icon":224},"i-lucide-folder-code",{"title":5,"path":226,"stem":227},"/","index",{"id":229,"title":63,"body":230,"description":1860,"extension":1861,"meta":1862,"navigation":1863,"path":64,"seo":1864,"stem":65,"__hash__":1865},"content/1.docs/7.cache.md",{"type":231,"value":232,"toc":1852,"icon":66},"minimark",[233,240,245,253,266,364,370,377,394,398,405,408,708,719,772,777,1056,1060,1063,1070,1137,1149,1250,1254,1261,1287,1297,1367,1373,1451,1454,1463,1609,1613,1622,1670,1673,1765,1768,1791,1794,1842,1848],[234,235,236],"warning",{},[237,238,239],"p",{},"Nitro v3 Alpha docs are a work in progress — expect updates, rough edges, and occasional inaccuracies.",[241,242,244],"h2",{"id":243},"cached-handlers","Cached handlers",[237,246,247,248,252],{},"To cache an event handler, you simply need to use the ",[249,250,251],"code",{},"defineCachedHandler"," method.",[237,254,255,256,259,260,265],{},"It works like ",[249,257,258],{},"defineHandler"," but with an second parameter for the ",[261,262,264],"a",{"href":263},"#options","cache options",".",[267,268,273],"pre",{"className":269,"code":270,"filename":271,"language":272,"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",[249,274,275,298,305,334,345],{"__ignoreMap":5},[276,277,280,284,288,291,295],"span",{"class":278,"line":279},"line",1,[276,281,283],{"class":282},"so5gQ","import",[276,285,287],{"class":286},"slsVL"," { defineCachedHandler } ",[276,289,290],{"class":282},"from",[276,292,294],{"class":293},"sfrk1"," \"nitro/cache\"",[276,296,297],{"class":286},";\n",[276,299,301],{"class":278,"line":300},2,[276,302,304],{"emptyLinePlaceholder":303},true,"\n",[276,306,308,311,314,318,321,325,328,331],{"class":278,"line":307},3,[276,309,310],{"class":282},"export",[276,312,313],{"class":282}," default",[276,315,317],{"class":316},"shcOC"," defineCachedHandler",[276,319,320],{"class":286},"((",[276,322,324],{"class":323},"sQHwn","event",[276,326,327],{"class":286},") ",[276,329,330],{"class":282},"=>",[276,332,333],{"class":286}," {\n",[276,335,337,340,343],{"class":278,"line":336},4,[276,338,339],{"class":282},"  return",[276,341,342],{"class":293}," \"I am cached for an hour\"",[276,344,297],{"class":286},[276,346,348,351,355,358,361],{"class":278,"line":347},5,[276,349,350],{"class":286},"}, { maxAge: ",[276,352,354],{"class":353},"suiK_","60",[276,356,357],{"class":282}," *",[276,359,360],{"class":353}," 60",[276,362,363],{"class":286}," });\n",[237,365,366,367,265],{},"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 ",[249,368,369],{},"swr: false",[237,371,372,373,376],{},"See the ",[261,374,375],{"href":263},"options"," section for more details about the available options.",[378,379,380],"important",{},[237,381,382,386,387,393],{},[383,384,385],"strong",{},"Request headers are dropped"," when handling cached responses. Use the ",[261,388,389,392],{"href":263},[249,390,391],{},"varies"," option"," to consider specific headers when caching and serving the responses.",[241,395,397],{"id":396},"cached-functions","Cached functions",[237,399,400,401,404],{},"You can also cache a function using the ",[249,402,403],{},"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.",[237,406,407],{},"For example, you might want to cache the result of an API call for one hour:",[267,409,412],{"className":269,"code":410,"filename":411,"language":272,"meta":5,"style":5},"import { defineHandler, type H3Event } from \"nitro/h3\";\nimport { defineHandler, defineCachedFunction } from \"nitro/cache\";\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",[249,413,414,434,447,451,477,497,531,536,544,550,555,588,636,641,649,655,670,681,703],{"__ignoreMap":5},[276,415,416,418,421,424,427,429,432],{"class":278,"line":279},[276,417,283],{"class":282},[276,419,420],{"class":286}," { defineHandler, ",[276,422,423],{"class":282},"type",[276,425,426],{"class":286}," H3Event } ",[276,428,290],{"class":282},[276,430,431],{"class":293}," \"nitro/h3\"",[276,433,297],{"class":286},[276,435,436,438,441,443,445],{"class":278,"line":300},[276,437,283],{"class":282},[276,439,440],{"class":286}," { defineHandler, defineCachedFunction } ",[276,442,290],{"class":282},[276,444,294],{"class":293},[276,446,297],{"class":286},[276,448,449],{"class":278,"line":307},[276,450,304],{"emptyLinePlaceholder":303},[276,452,453,455,457,460,463,466,469,471,473,475],{"class":278,"line":336},[276,454,310],{"class":282},[276,456,313],{"class":282},[276,458,459],{"class":316}," defineHandler",[276,461,462],{"class":286},"(",[276,464,465],{"class":282},"async",[276,467,468],{"class":286}," (",[276,470,324],{"class":323},[276,472,327],{"class":286},[276,474,330],{"class":282},[276,476,333],{"class":286},[276,478,479,482,485,488,491,494],{"class":278,"line":347},[276,480,481],{"class":282},"  const",[276,483,484],{"class":286}," { ",[276,486,487],{"class":353},"repo",[276,489,490],{"class":286}," } ",[276,492,493],{"class":282},"=",[276,495,496],{"class":286}," event.context.params;\n",[276,498,500,502,505,508,511,514,517,520,523,525,528],{"class":278,"line":499},6,[276,501,481],{"class":282},[276,503,504],{"class":353}," stars",[276,506,507],{"class":282}," =",[276,509,510],{"class":282}," await",[276,512,513],{"class":316}," cachedGHStars",[276,515,516],{"class":286},"(repo).",[276,518,519],{"class":316},"catch",[276,521,522],{"class":286},"(() ",[276,524,330],{"class":282},[276,526,527],{"class":353}," 0",[276,529,530],{"class":286},")\n",[276,532,534],{"class":278,"line":533},7,[276,535,304],{"emptyLinePlaceholder":303},[276,537,539,541],{"class":278,"line":538},8,[276,540,339],{"class":282},[276,542,543],{"class":286}," { repo, stars }\n",[276,545,547],{"class":278,"line":546},9,[276,548,549],{"class":286},"});\n",[276,551,553],{"class":278,"line":552},10,[276,554,304],{"emptyLinePlaceholder":303},[276,556,558,561,563,565,568,570,572,574,576,579,582,584,586],{"class":278,"line":557},11,[276,559,560],{"class":282},"const",[276,562,513],{"class":353},[276,564,507],{"class":282},[276,566,567],{"class":316}," defineCachedFunction",[276,569,462],{"class":286},[276,571,465],{"class":282},[276,573,468],{"class":286},[276,575,487],{"class":323},[276,577,578],{"class":282},":",[276,580,581],{"class":353}," string",[276,583,327],{"class":286},[276,585,330],{"class":282},[276,587,333],{"class":286},[276,589,591,593,596,598,600,603,605,608,610,613,616,619,621,624,627,630,633],{"class":278,"line":590},12,[276,592,481],{"class":282},[276,594,595],{"class":353}," data",[276,597,507],{"class":282},[276,599,510],{"class":282},[276,601,602],{"class":316}," fetch",[276,604,462],{"class":286},[276,606,607],{"class":293},"`https://api.github.com/repos/${",[276,609,487],{"class":286},[276,611,612],{"class":293},"}`",[276,614,615],{"class":286},").",[276,617,618],{"class":316},"then",[276,620,462],{"class":286},[276,622,623],{"class":323},"res",[276,625,626],{"class":282}," =>",[276,628,629],{"class":286}," res.",[276,631,632],{"class":316},"json",[276,634,635],{"class":286},"());\n",[276,637,639],{"class":278,"line":638},13,[276,640,304],{"emptyLinePlaceholder":303},[276,642,644,646],{"class":278,"line":643},14,[276,645,339],{"class":282},[276,647,648],{"class":286}," data.stargazers_count;\n",[276,650,652],{"class":278,"line":651},15,[276,653,654],{"class":286},"}, {\n",[276,656,658,661,663,665,667],{"class":278,"line":657},16,[276,659,660],{"class":286},"  maxAge: ",[276,662,354],{"class":353},[276,664,357],{"class":282},[276,666,360],{"class":353},[276,668,669],{"class":286},",\n",[276,671,673,676,679],{"class":278,"line":672},17,[276,674,675],{"class":286},"  name: ",[276,677,678],{"class":293},"\"ghStars\"",[276,680,669],{"class":286},[276,682,684,687,690,692,694,696,698,700],{"class":278,"line":683},18,[276,685,686],{"class":316},"  getKey",[276,688,689],{"class":286},": (",[276,691,487],{"class":323},[276,693,578],{"class":282},[276,695,581],{"class":353},[276,697,327],{"class":286},[276,699,330],{"class":282},[276,701,702],{"class":286}," repo\n",[276,704,706],{"class":278,"line":705},19,[276,707,549],{"class":286},[237,709,710,711,714,715,718],{},"The stars will be cached in development inside ",[249,712,713],{},".nitro/cache/functions/ghStars/\u003Cowner>/\u003Crepo>.json"," with ",[249,716,717],{},"value"," being the number of stars.",[267,720,723],{"className":721,"code":722,"language":632,"meta":5,"style":5},"language-json shiki shiki-themes github-light github-dark github-dark","{\"expires\":1677851092249,\"value\":43991,\"mtime\":1677847492540,\"integrity\":\"ZUHcsxCWEH\"}\n",[249,724,725],{"__ignoreMap":5},[276,726,727,730,733,735,738,741,744,746,749,751,754,756,759,761,764,766,769],{"class":278,"line":279},[276,728,729],{"class":286},"{",[276,731,732],{"class":353},"\"expires\"",[276,734,578],{"class":286},[276,736,737],{"class":353},"1677851092249",[276,739,740],{"class":286},",",[276,742,743],{"class":353},"\"value\"",[276,745,578],{"class":286},[276,747,748],{"class":353},"43991",[276,750,740],{"class":286},[276,752,753],{"class":353},"\"mtime\"",[276,755,578],{"class":286},[276,757,758],{"class":353},"1677847492540",[276,760,740],{"class":286},[276,762,763],{"class":353},"\"integrity\"",[276,765,578],{"class":286},[276,767,768],{"class":293},"\"ZUHcsxCWEH\"",[276,770,771],{"class":286},"}\n",[378,773,774],{},[237,775,776],{},"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…",[778,779,780,783],"callout",{},[237,781,782],{},"If you are using edge workers to host your application, you should follow the instructions below.",[784,785,787,794,805,1053],"collapsible",{"name":786},"Edge workers instructions",[237,788,789,790,793],{},"In edge workers, the instance is destroyed after each request. Nitro automatically uses ",[249,791,792],{},"event.waitUntil"," to keep the instance alive while the cache is being updated while the response is sent to the client.",[237,795,796,797],{},"To ensure that your cached functions work as expected in edge workers, ",[383,798,799,800,802,803,265],{},"you should always pass the ",[249,801,324],{}," as the first argument to the function using ",[249,804,403],{},[267,806,809],{"className":269,"code":807,"filename":411,"highlights":808,"language":272,"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",[347,552,672],[249,810,811,824,828,832,854,870,895,899,905,909,914,952,988,992,998,1002,1014,1023,1049],{"__ignoreMap":5},[276,812,813,815,818,820,822],{"class":278,"line":279},[276,814,283],{"class":282},[276,816,817],{"class":286}," { defineCachedFunction } ",[276,819,290],{"class":282},[276,821,294],{"class":293},[276,823,297],{"class":286},[276,825,826],{"class":278,"line":300},[276,827,304],{"emptyLinePlaceholder":303},[276,829,830],{"class":278,"line":307},[276,831,304],{"emptyLinePlaceholder":303},[276,833,834,836,838,840,842,844,846,848,850,852],{"class":278,"line":336},[276,835,310],{"class":282},[276,837,313],{"class":282},[276,839,459],{"class":316},[276,841,462],{"class":286},[276,843,465],{"class":282},[276,845,468],{"class":286},[276,847,324],{"class":323},[276,849,327],{"class":286},[276,851,330],{"class":282},[276,853,333],{"class":286},[276,855,858,860,862,864,866,868],{"class":856,"line":347},[278,857],"highlight",[276,859,481],{"class":282},[276,861,484],{"class":286},[276,863,487],{"class":353},[276,865,490],{"class":286},[276,867,493],{"class":282},[276,869,496],{"class":286},[276,871,872,874,876,878,880,882,885,887,889,891,893],{"class":278,"line":499},[276,873,481],{"class":282},[276,875,504],{"class":353},[276,877,507],{"class":282},[276,879,510],{"class":282},[276,881,513],{"class":316},[276,883,884],{"class":286},"(event, repo).",[276,886,519],{"class":316},[276,888,522],{"class":286},[276,890,330],{"class":282},[276,892,527],{"class":353},[276,894,530],{"class":286},[276,896,897],{"class":278,"line":533},[276,898,304],{"emptyLinePlaceholder":303},[276,900,901,903],{"class":278,"line":538},[276,902,339],{"class":282},[276,904,543],{"class":286},[276,906,907],{"class":278,"line":546},[276,908,549],{"class":286},[276,910,912],{"class":911,"line":552},[278,857],[276,913,304],{"emptyLinePlaceholder":303},[276,915,916,918,920,922,924,926,928,930,932,934,937,940,942,944,946,948,950],{"class":278,"line":557},[276,917,560],{"class":282},[276,919,513],{"class":353},[276,921,507],{"class":282},[276,923,567],{"class":316},[276,925,462],{"class":286},[276,927,465],{"class":282},[276,929,468],{"class":286},[276,931,324],{"class":323},[276,933,578],{"class":282},[276,935,936],{"class":316}," H3Event",[276,938,939],{"class":286},", ",[276,941,487],{"class":323},[276,943,578],{"class":282},[276,945,581],{"class":353},[276,947,327],{"class":286},[276,949,330],{"class":282},[276,951,333],{"class":286},[276,953,954,956,958,960,962,964,966,968,970,972,974,976,978,980,982,984,986],{"class":278,"line":590},[276,955,481],{"class":282},[276,957,595],{"class":353},[276,959,507],{"class":282},[276,961,510],{"class":282},[276,963,602],{"class":316},[276,965,462],{"class":286},[276,967,607],{"class":293},[276,969,487],{"class":286},[276,971,612],{"class":293},[276,973,615],{"class":286},[276,975,618],{"class":316},[276,977,462],{"class":286},[276,979,623],{"class":323},[276,981,626],{"class":282},[276,983,629],{"class":286},[276,985,632],{"class":316},[276,987,635],{"class":286},[276,989,990],{"class":278,"line":638},[276,991,304],{"emptyLinePlaceholder":303},[276,993,994,996],{"class":278,"line":643},[276,995,339],{"class":282},[276,997,648],{"class":286},[276,999,1000],{"class":278,"line":651},[276,1001,654],{"class":286},[276,1003,1004,1006,1008,1010,1012],{"class":278,"line":657},[276,1005,660],{"class":286},[276,1007,354],{"class":353},[276,1009,357],{"class":282},[276,1011,360],{"class":353},[276,1013,669],{"class":286},[276,1015,1017,1019,1021],{"class":1016,"line":672},[278,857],[276,1018,675],{"class":286},[276,1020,678],{"class":293},[276,1022,669],{"class":286},[276,1024,1025,1027,1029,1031,1033,1035,1037,1039,1041,1043,1045,1047],{"class":278,"line":683},[276,1026,686],{"class":316},[276,1028,689],{"class":286},[276,1030,324],{"class":323},[276,1032,578],{"class":282},[276,1034,936],{"class":316},[276,1036,939],{"class":286},[276,1038,487],{"class":323},[276,1040,578],{"class":282},[276,1042,581],{"class":353},[276,1044,327],{"class":286},[276,1046,330],{"class":282},[276,1048,702],{"class":286},[276,1050,1051],{"class":278,"line":705},[276,1052,549],{"class":286},[237,1054,1055],{},"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.",[241,1057,1059],{"id":1058},"using-route-rules","Using route rules",[237,1061,1062],{},"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.",[237,1064,1065,1066,1069],{},"Cache all the blog routes for 1 hour with ",[249,1067,1068],{},"stale-while-revalidate"," behavior:",[267,1071,1074],{"className":269,"code":1072,"filename":1073,"language":272,"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",[249,1075,1076,1090,1094,1106,1111,1128,1133],{"__ignoreMap":5},[276,1077,1078,1080,1083,1085,1088],{"class":278,"line":279},[276,1079,283],{"class":282},[276,1081,1082],{"class":286}," { defineNitroConfig } ",[276,1084,290],{"class":282},[276,1086,1087],{"class":293}," \"nitro/config\"",[276,1089,297],{"class":286},[276,1091,1092],{"class":278,"line":300},[276,1093,304],{"emptyLinePlaceholder":303},[276,1095,1096,1098,1100,1103],{"class":278,"line":307},[276,1097,310],{"class":282},[276,1099,313],{"class":282},[276,1101,1102],{"class":316}," defineNitroConfig",[276,1104,1105],{"class":286},"({\n",[276,1107,1108],{"class":278,"line":336},[276,1109,1110],{"class":286},"  routeRules: {\n",[276,1112,1113,1116,1119,1121,1123,1125],{"class":278,"line":347},[276,1114,1115],{"class":293},"    \"/blog/**\"",[276,1117,1118],{"class":286},": { cache: { maxAge: ",[276,1120,354],{"class":353},[276,1122,357],{"class":282},[276,1124,360],{"class":353},[276,1126,1127],{"class":286}," } },\n",[276,1129,1130],{"class":278,"line":499},[276,1131,1132],{"class":286},"  },\n",[276,1134,1135],{"class":278,"line":533},[276,1136,549],{"class":286},[237,1138,1139,1140,1144,1145,1148],{},"If we want to use a ",[261,1141,1143],{"href":1142},"#cache-storage","custom cache storage"," mount point, we can use the ",[249,1146,1147],{},"base"," option.",[267,1150,1152],{"className":269,"code":1151,"filename":1073,"language":272,"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",[249,1153,1154,1166,1170,1180,1185,1190,1200,1210,1215,1219,1223,1242,1246],{"__ignoreMap":5},[276,1155,1156,1158,1160,1162,1164],{"class":278,"line":279},[276,1157,283],{"class":282},[276,1159,1082],{"class":286},[276,1161,290],{"class":282},[276,1163,1087],{"class":293},[276,1165,297],{"class":286},[276,1167,1168],{"class":278,"line":300},[276,1169,304],{"emptyLinePlaceholder":303},[276,1171,1172,1174,1176,1178],{"class":278,"line":307},[276,1173,310],{"class":282},[276,1175,313],{"class":282},[276,1177,1102],{"class":316},[276,1179,1105],{"class":286},[276,1181,1182],{"class":278,"line":336},[276,1183,1184],{"class":286},"  storage: {\n",[276,1186,1187],{"class":278,"line":347},[276,1188,1189],{"class":286},"    redis: {\n",[276,1191,1192,1195,1198],{"class":278,"line":499},[276,1193,1194],{"class":286},"      driver: ",[276,1196,1197],{"class":293},"\"redis\"",[276,1199,669],{"class":286},[276,1201,1202,1205,1208],{"class":278,"line":533},[276,1203,1204],{"class":286},"      url: ",[276,1206,1207],{"class":293},"\"redis://localhost:6379\"",[276,1209,669],{"class":286},[276,1211,1212],{"class":278,"line":538},[276,1213,1214],{"class":286},"    },\n",[276,1216,1217],{"class":278,"line":546},[276,1218,1132],{"class":286},[276,1220,1221],{"class":278,"line":552},[276,1222,1110],{"class":286},[276,1224,1225,1227,1229,1231,1233,1235,1238,1240],{"class":278,"line":557},[276,1226,1115],{"class":293},[276,1228,1118],{"class":286},[276,1230,354],{"class":353},[276,1232,357],{"class":282},[276,1234,360],{"class":353},[276,1236,1237],{"class":286},", base: ",[276,1239,1197],{"class":293},[276,1241,1127],{"class":286},[276,1243,1244],{"class":278,"line":590},[276,1245,1132],{"class":286},[276,1247,1248],{"class":278,"line":638},[276,1249,549],{"class":286},[241,1251,1253],{"id":1252},"cache-storage","Cache storage",[237,1255,1256,1257,1260],{},"Nitro stores the data in the ",[249,1258,1259],{},"cache"," storage mount point.",[1262,1263,1264,1275],"ul",{},[1265,1266,1267,1268,1274],"li",{},"In production, it will use the ",[261,1269,1273],{"href":1270,"rel":1271},"https://unstorage.unjs.io/drivers/memory",[1272],"nofollow","memory driver"," by default.",[1265,1276,1277,1278,1283,1284,615],{},"In development, it will use the ",[261,1279,1282],{"href":1280,"rel":1281},"https://unstorage.unjs.io/drivers/fs",[1272],"filesystem driver",", writing to a temporary dir (",[249,1285,1286],{},".nitro/cache",[237,1288,1289,1290,1292,1293,1296],{},"To overwrite the production storage, set the ",[249,1291,1259],{}," mount point using the ",[249,1294,1295],{},"storage"," option:",[267,1298,1300],{"className":269,"code":1299,"filename":1073,"language":272,"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",[249,1301,1302,1314,1318,1328,1332,1337,1346,1352,1357,1362],{"__ignoreMap":5},[276,1303,1304,1306,1308,1310,1312],{"class":278,"line":279},[276,1305,283],{"class":282},[276,1307,1082],{"class":286},[276,1309,290],{"class":282},[276,1311,1087],{"class":293},[276,1313,297],{"class":286},[276,1315,1316],{"class":278,"line":300},[276,1317,304],{"emptyLinePlaceholder":303},[276,1319,1320,1322,1324,1326],{"class":278,"line":307},[276,1321,310],{"class":282},[276,1323,313],{"class":282},[276,1325,1102],{"class":316},[276,1327,1105],{"class":286},[276,1329,1330],{"class":278,"line":336},[276,1331,1184],{"class":286},[276,1333,1334],{"class":278,"line":347},[276,1335,1336],{"class":286},"    cache: {\n",[276,1338,1339,1341,1344],{"class":278,"line":499},[276,1340,1194],{"class":286},[276,1342,1343],{"class":293},"'redis'",[276,1345,669],{"class":286},[276,1347,1348],{"class":278,"line":533},[276,1349,1351],{"class":1350},"sCsY4","      /* redis connector options */\n",[276,1353,1354],{"class":278,"line":538},[276,1355,1356],{"class":286},"    }\n",[276,1358,1359],{"class":278,"line":546},[276,1360,1361],{"class":286},"  }\n",[276,1363,1364],{"class":278,"line":552},[276,1365,1366],{"class":286},"})\n",[237,1368,1369,1370,1296],{},"In development, you can also overwrite the cache mount point using the ",[249,1371,1372],{},"devStorage",[267,1374,1376],{"className":269,"code":1375,"filename":1073,"language":272,"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",[249,1377,1378,1390,1394,1404,1408,1412,1417,1421,1425,1430,1434,1439,1443,1447],{"__ignoreMap":5},[276,1379,1380,1382,1384,1386,1388],{"class":278,"line":279},[276,1381,283],{"class":282},[276,1383,1082],{"class":286},[276,1385,290],{"class":282},[276,1387,1087],{"class":293},[276,1389,297],{"class":286},[276,1391,1392],{"class":278,"line":300},[276,1393,304],{"emptyLinePlaceholder":303},[276,1395,1396,1398,1400,1402],{"class":278,"line":307},[276,1397,310],{"class":282},[276,1399,313],{"class":282},[276,1401,1102],{"class":316},[276,1403,1105],{"class":286},[276,1405,1406],{"class":278,"line":336},[276,1407,1184],{"class":286},[276,1409,1410],{"class":278,"line":347},[276,1411,1336],{"class":286},[276,1413,1414],{"class":278,"line":499},[276,1415,1416],{"class":1350},"      // production cache storage\n",[276,1418,1419],{"class":278,"line":533},[276,1420,1214],{"class":286},[276,1422,1423],{"class":278,"line":538},[276,1424,1132],{"class":286},[276,1426,1427],{"class":278,"line":546},[276,1428,1429],{"class":286},"  devStorage: {\n",[276,1431,1432],{"class":278,"line":552},[276,1433,1336],{"class":286},[276,1435,1436],{"class":278,"line":557},[276,1437,1438],{"class":1350},"      // development cache storage\n",[276,1440,1441],{"class":278,"line":590},[276,1442,1356],{"class":286},[276,1444,1445],{"class":278,"line":638},[276,1446,1361],{"class":286},[276,1448,1449],{"class":278,"line":643},[276,1450,1366],{"class":286},[241,1452,1453],{"id":375},"Options",[237,1455,1456,1457,1459,1460,1462],{},"The ",[249,1458,251],{}," and ",[249,1461,403],{}," functions accept the following options:",[1464,1465,1466,1479,1489,1503,1517,1530,1543,1560,1575,1585,1593],"field-group",{},[1467,1468,1470],"field",{"name":1147,"type":1469},"string",[237,1471,1472,1473,1476,1477,265],{},"Name of the storage mountpoint to use for caching. ",[1474,1475],"br",{},"\nDefault to ",[249,1478,1259],{},[1467,1480,1482],{"name":1481,"type":1469},"name",[237,1483,1484,1485,1488],{},"Guessed from function name if not provided, and falls back to ",[249,1486,1487],{},"'_'"," otherwise.",[1467,1490,1492],{"name":1491,"type":1469},"group",[237,1493,1494,1495,1498,1499,1502],{},"Defaults to ",[249,1496,1497],{},"'nitro/handlers'"," for handlers and ",[249,1500,1501],{},"'nitro/functions'"," for functions.",[1467,1504,1507],{"name":1505,"type":1506},"getKey()","(...args) => string",[237,1508,1509,1510,1513,1514,1516],{},"A function that accepts the same arguments as the original function and returns a cache key (",[249,1511,1512],{},"String","). ",[1474,1515],{},"\nIf not provided, a built-in hash function will be used to generate a key based on the function arguments.",[1467,1518,1520],{"name":1519,"type":1469},"integrity",[237,1521,1522,1523,1525,1526,1529],{},"A value that invalidates the cache when changed. ",[1474,1524],{},"\nBy default, it is computed from ",[383,1527,1528],{},"function code",", used in development to invalidate the cache when the function code changes.",[1467,1531,1534],{"name":1532,"type":1533},"maxAge","number",[237,1535,1536,1537,1476,1539,1542],{},"Maximum age that cache is valid, in seconds. ",[1474,1538],{},[249,1540,1541],{},"1"," (second).",[1467,1544,1546],{"name":1545,"type":1533},"staleMaxAge",[237,1547,1548,1549,1552,1553,1555,1556,1559],{},"Maximum age that a stale cache is valid, in seconds. If set to ",[249,1550,1551],{},"-1"," a stale value will still be sent to the client while the cache updates in the background. ",[1474,1554],{},"\nDefaults to ",[249,1557,1558],{},"0"," (disabled).",[1467,1561,1564],{"name":1562,"type":1563},"swr","boolean",[237,1565,1566,1567,1569,1570,1555,1572,265],{},"Enable ",[249,1568,1068],{}," behavior to serve a stale cached response while asynchronously revalidating it. ",[1474,1571],{},[249,1573,1574],{},"true",[1467,1576,1579],{"name":1577,"type":1578},"shouldInvalidateCache()","(..args) => boolean",[237,1580,1581,1582,1584],{},"A function that returns a ",[249,1583,1563],{}," to invalidate the current cache and create a new one.",[1467,1586,1588],{"name":1587,"type":1578},"shouldBypassCache()",[237,1589,1581,1590,1592],{},[249,1591,1563],{}," to bypass the current cache without invalidating the existing entry.",[1467,1594,1596],{"name":391,"type":1595},"string[]",[237,1597,1598,1599,1604,1605,1608],{},"An array of request headers to be considered for the cache, ",[261,1600,1603],{"href":1601,"rel":1602},"https://github.com/nitrojs/nitro/issues/1031",[1272],"learn more",". If utilizing in a multi-tenant environment, you may want to pass ",[249,1606,1607],{},"['host', 'x-forwarded-host']"," to ensure these headers are not discarded and that the cache is unique per tenant.",[241,1610,1612],{"id":1611},"cache-keys-and-invalidation","Cache keys and invalidation",[237,1614,1615,1616,1618,1619,1621],{},"When using the ",[249,1617,403],{}," or ",[249,1620,251],{}," functions, the cache key is generated using the following pattern:",[267,1623,1625],{"className":269,"code":1624,"language":272,"meta":5,"style":5},"`${options.group}:${options.name}:${options.getKey(...args)}.json`\n",[249,1626,1627],{"__ignoreMap":5},[276,1628,1629,1632,1634,1636,1638,1641,1643,1645,1647,1649,1651,1653,1656,1658,1661,1664,1667],{"class":278,"line":279},[276,1630,1631],{"class":293},"`${",[276,1633,375],{"class":286},[276,1635,265],{"class":293},[276,1637,1491],{"class":286},[276,1639,1640],{"class":293},"}:${",[276,1642,375],{"class":286},[276,1644,265],{"class":293},[276,1646,1481],{"class":286},[276,1648,1640],{"class":293},[276,1650,375],{"class":286},[276,1652,265],{"class":293},[276,1654,1655],{"class":316},"getKey",[276,1657,462],{"class":293},[276,1659,1660],{"class":282},"...",[276,1662,1663],{"class":286},"args",[276,1665,1666],{"class":293},")",[276,1668,1669],{"class":293},"}.json`\n",[237,1671,1672],{},"For example, the following function:",[267,1674,1676],{"className":269,"code":1675,"language":272,"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",[249,1677,1678,1690,1694,1711,1727,1731,1740,1749,1761],{"__ignoreMap":5},[276,1679,1680,1682,1684,1686,1688],{"class":278,"line":279},[276,1681,283],{"class":282},[276,1683,817],{"class":286},[276,1685,290],{"class":282},[276,1687,294],{"class":293},[276,1689,297],{"class":286},[276,1691,1692],{"class":278,"line":300},[276,1693,304],{"emptyLinePlaceholder":303},[276,1695,1696,1698,1701,1703,1705,1707,1709],{"class":278,"line":307},[276,1697,560],{"class":282},[276,1699,1700],{"class":353}," getAccessToken",[276,1702,507],{"class":282},[276,1704,567],{"class":316},[276,1706,522],{"class":286},[276,1708,330],{"class":282},[276,1710,333],{"class":286},[276,1712,1713,1715,1718,1721,1724],{"class":278,"line":336},[276,1714,339],{"class":282},[276,1716,1717],{"class":316}," String",[276,1719,1720],{"class":286},"(Date.",[276,1722,1723],{"class":316},"now",[276,1725,1726],{"class":286},"())\n",[276,1728,1729],{"class":278,"line":347},[276,1730,654],{"class":286},[276,1732,1733,1735,1738],{"class":278,"line":499},[276,1734,660],{"class":286},[276,1736,1737],{"class":353},"10",[276,1739,669],{"class":286},[276,1741,1742,1744,1747],{"class":278,"line":533},[276,1743,675],{"class":286},[276,1745,1746],{"class":293},"\"getAccessToken\"",[276,1748,669],{"class":286},[276,1750,1751,1753,1756,1758],{"class":278,"line":538},[276,1752,686],{"class":316},[276,1754,1755],{"class":286},": () ",[276,1757,330],{"class":282},[276,1759,1760],{"class":293}," \"default\"\n",[276,1762,1763],{"class":278,"line":546},[276,1764,549],{"class":286},[237,1766,1767],{},"Will generate the following cache key:",[267,1769,1771],{"className":269,"code":1770,"language":272,"meta":5,"style":5},"nitro:functions:getAccessToken:default.json\n",[249,1772,1773],{"__ignoreMap":5},[276,1774,1775,1778,1780,1783,1785,1788],{"class":278,"line":279},[276,1776,1777],{"class":316},"nitro",[276,1779,578],{"class":286},[276,1781,1782],{"class":316},"functions",[276,1784,578],{"class":286},[276,1786,1787],{"class":316},"getAccessToken",[276,1789,1790],{"class":286},":default.json\n",[237,1792,1793],{},"You can invalidate the cached function entry with:",[267,1795,1797],{"className":269,"code":1796,"language":272,"meta":5,"style":5},"import { useStorage } from \"nitro/storage\";\n\nawait useStorage('cache').removeItem('nitro:functions:getAccessToken:default.json')\n",[249,1798,1799,1813,1817],{"__ignoreMap":5},[276,1800,1801,1803,1806,1808,1811],{"class":278,"line":279},[276,1802,283],{"class":282},[276,1804,1805],{"class":286}," { useStorage } ",[276,1807,290],{"class":282},[276,1809,1810],{"class":293}," \"nitro/storage\"",[276,1812,297],{"class":286},[276,1814,1815],{"class":278,"line":300},[276,1816,304],{"emptyLinePlaceholder":303},[276,1818,1819,1822,1825,1827,1830,1832,1835,1837,1840],{"class":278,"line":307},[276,1820,1821],{"class":282},"await",[276,1823,1824],{"class":316}," useStorage",[276,1826,462],{"class":286},[276,1828,1829],{"class":293},"'cache'",[276,1831,615],{"class":286},[276,1833,1834],{"class":316},"removeItem",[276,1836,462],{"class":286},[276,1838,1839],{"class":293},"'nitro:functions:getAccessToken:default.json'",[276,1841,530],{"class":286},[1843,1844,1845],"read-more",{"to":69},[237,1846,1847],{},"Read more about the Nitro storage.",[1849,1850,1851],"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":300,"depth":300,"links":1853},[1854,1855,1856,1857,1858,1859],{"id":243,"depth":300,"text":244},{"id":396,"depth":300,"text":397},{"id":1058,"depth":300,"text":1059},{"id":1252,"depth":300,"text":1253},{"id":375,"depth":300,"text":1453},{"id":1611,"depth":300,"text":1612},"Nitro provides a caching system built on top of the storage layer.","md",{"icon":66},{"icon":66},{"title":63,"description":1860},"WLcTEjeK9EmgUIVHJXv6mLRQa7sf0Il-c5O6dZPHusE",[1867,1869],{"title":58,"path":59,"stem":60,"description":1868,"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":1870,"icon":71,"children":-1},"Nitro provides a built-in storage layer that can abstract filesystem or database or any other data source.",1773176970106]