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