liveBook · Manning

Caching

As explained in Build AI-Enhanced Web Apps

The technique of storing computed or retrieved data temporarily so that later requests can return it without repeating the original work.

Caching keeps a reusable result close to an application so later requests need not repeat the same work. In an AI application, a cache layer can hold frequently accessed data or model responses, reducing latency and computational load. Redis and Memcached are possible cache stores. section 1.2.1

In Next.js, choose caching behavior according to how often the result changes:

  • For a changing chat response, set `export const dynamic = 'force-dynamic'` in the route handler so requests are reevaluated on the server. The default `auto` setting can cache GET responses. section 2.8.6
  • For an individual fetch, use `cache: 'no-store'` for dynamic data or `next: { revalidate: 3600 }` to set a revalidation interval for static data. section 2.8.7
  • For a static page that needs occasional updates, incremental static regeneration can serve the old page after its revalidation interval while generating a new one in the background. section 2.8.7

Reuse interview feedback

An interview assistant caches LLM-generated feedback in Redis under `feedback:${sessionId}`. A later visit to the feedback page can reuse that result instead of regenerating it. This is distinct from its Redis session records, which the sidebar retrieves to list past interviews. section 10.1.3

Treat caching as a deployment decision as well as a code setting: assess latency, apply local caching where appropriate, and optimize API calls and data retrieval. Do not cache a frequently changing response merely because a route supports it. section 9.6.2 section 2.8.6

How Build AI-Enhanced Web Apps covers it

How deep it goes
Shows Next.js route and fetch settings and a Redis feedback key, but does not specify cache invalidation or Redis cache implementation.
Examples
Uses a dynamic chat API route, per-fetch revalidation options, and Redis-cached interview feedback.
What you can do after
Apply it via Next.js route and fetch settings, or use Redis to avoid regenerating session feedback.
How it connects
Links caching to Next.js route handlers, the fetch API, incremental static regeneration, Redis, and LLM latency.

Also explained in

Compare how 38 books explain caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.