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