Caching in Nitro 💾

Published 2024-07-26
Caching in Nitro is one of its key aspects. In this video, we have a look at how to achieve caching in your Nitro-based application. Also works in Nuxt!

#nitro #nuxt #vue

---
Links and Resources:

🔗 10% Off for vuejs.de Conf with Code LICHTER conf.vuejs.de/tickets/?voucher=LICHTER

📺 ‪@DejaVueFm‬ #E018 - Insights from the Nuxt Team Retreat

---
Chaptermarks:

00:00 Intro
00:11 What is Nitro special about
00:38 Focus on caching
01:00 Our demo app
01:47 Caching with route rules
04:12 Enabling server-side SWR
05:35 Stale max age
06:28 Using defineCachedEventHandler
07:32 Change the cache key
09:54 Different storage providers
11:23 Further options
12:04 defineCachedFunction
16:27 Cache Invalidation
21:42 Wrapping

All Comments (21)
  • I had no idea this was all doable within Nitro, going to set this up asap
  • @mauriceputz
    Are you reading my mind? Always when I have a project where I need a specific answer video too, I see you uploaded a video to it a few hours or days ago, which nails the topic directly and helps a lot! Thank you mate.
  • @gro967
    Used Nitro caching the first time two years ago, was about time someone exposes that to the world :)
  • @da-ker
    Very nice introduction to caching options. Thank you!
  • @jdaws47
    Thank you for your videos. They have been a tremendous help on a project I’m working on.
  • @web-code-maker
    Всё очень понятно и классно рассказал. Спасибо друг
  • @heyjitendra
    Wow this is amazing. I have used hono but unjs seems good too..
  • @ralacerda12
    Amazing video! Nitro keeps blowing my mind on how simple it's to get it running and doing complex stuff. But a question not totally related to the video, but if you build a project like this for nitro (stand alone) and you want to use with an spa (without nuxt or even without vue), how can I get the types from the nitro project? Do I need to setup a monorepo?
  • @paradox3210
    Is it possible to use a catch-all route (server/api/[...].ts) and a specific route rule in the config at the same time? I want to cache one particular route (/api/settings) 🤔
  • @solvedfyi
    I suppose if you're gonna keep bringing up stuff super relevant to me I'm just going to have to subscribe
  • @LajonDJ
    @TheAlexLichter Is there a way to get all caches in a Nitro/Nuxt app? My use case is that I would like to build an admin interface, where you can invalidate caches :)
  • @LoFiLanes
    How to do cache with handler with auth ? if i use const session = await requireUserSession(event) from (Nuxt Auth Utils) inside, it doesn't work ( i use Nuxthub)
  • @impactsongs
    Greate Alexander! Thank you for the good tutorials. I have a question because i use cache in Nitro alot. How can i access a url parameter or slug inside a Info.server.vue component example. Because if i use useRoute() it is empty. I ask that because when i want to access something function from server i use Nitro and with this i can make a call directly from my server component.