Prefetch & Stream Cache
prefetchAction to pre-warm cache, useStreamActionQuery with persistent cache
Prefetch on Hover
Hover over a link to call prefetchAction which fetches data and stores it in the Nuxt payload cache. When you click, the data loads instantly from cache.
Todo List hover to prefetch
Search Results hover to prefetch
User Profile hover to prefetch
import { listTodos } from '#actions'
// Prefetch on hover — pre-warm the cache
async function onHover() {
await prefetchAction(listTodos)
}
// On click — useActionQuery finds cached data instantly
const { data } = useActionQuery(listTodos, undefined)useStreamActionQuery (Cached Stream)
Stream text once, and the result is cached in the Nuxt payload. Navigate away and come back — chunks are restored from cache instantly.
import { generateText } from '#actions'
const {
execute, stop, chunks, status,
fromCache, clearCache,
} = useStreamActionQuery(generateText, {
cacheKey: 'prefetch-demo',
})
// Stream once — cached automatically
await execute({ prompt: 'Hello' })
// On remount: chunks restored from cache
// fromCache.value === true