Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
GlossaryNovember 22, 20263 min read

What is caching?

Caching is why your second visit to a site is faster than the first, and why you sometimes see yesterday's version. The layers, the expiry question, and how to cache without serving stale data.

Startbase Team
Editorial ink illustration of a carpenter's apron pocket holding tools beside a distant closed toolbox, the hammer in ember orange

Key takeaways

  • A cache stores a copy of something expensive to fetch or compute so the next request is served faster.
  • Web apps cache at several layers: the browser, the CDN, the app's data layer and sometimes the server.
  • Every cache needs a rule for when its copy goes stale; fingerprinted file names and short lifetimes for live data handle most cases.

At its core, caching means keeping a copy of something that is slow or expensive to get (a file, a database result, a computed answer) somewhere faster, so the next request can use the copy instead of doing the work again. It is the reason a site loads faster on your second visit, and also the reason you sometimes see an old version right after an update.

An everyday example: the carpenter's apron

A carpenter keeps the toolbox across the room but carries a hammer, a pencil and a tape measure in an apron pocket. Ninety percent of the time, the needed tool is already at hand. Occasionally the pocket holds the wrong size screwdriver and a trip is unavoidable. That is a cache: a small, fast store of the things used most, backed by a bigger, slower source. A request served from the cache is a hit; one that has to go to the source is a miss.

The layers of caching in a web app

  1. 01Browser cache: scripts, styles, fonts and images saved on the visitor's device. Controlled by the `Cache-Control` header the server sends.
  2. 02CDN cache: copies of your files on servers near each visitor. See what is a CDN.
  3. 03App data cache: the app remembers results it already fetched. Open a product, go back, open it again, and it appears instantly while a fresh copy loads quietly. Libraries like React Query do this in React and React Native apps.
  4. 04Server or database cache: expensive results (a leaderboard, a daily report) computed once and stored, often in a key-value store, for a minute or an hour.

How long to cache: the hard part

There is an old programming joke that the two hardest problems are naming things and cache invalidation. The question is always "when is the copy too old?" Reasonable starting points:

  • Fingerprinted build files (names like `index-4f8a2c.js`): cache for a year. Each new build creates new names, so visitors never get a stale script. Vite does this by default.
  • The HTML page itself: cache briefly or revalidate on each visit, because it points at the latest file names.
  • A global leaderboard: 30 to 60 seconds is usually fine and saves thousands of identical queries.
  • A user's own cart, balance or messages: do not serve stale data. Refetch on focus, or update the cache the moment the user changes something.

Why it matters when building with Startbase

Some caching is handled for you. Startbase builds a snapshot of your project when you publish, and the live site only changes when you republish; while a republish builds, the current version stays live (publishing docs). Web projects start from Vite, which fingerprints file names, and mobile projects start from Expo with React Query included (Expo template docs). The decisions left to you are about your data: which screens can show slightly old information and which must always be fresh.

The home screen refetches everything every time the user opens it. Cache the product catalog for 10 minutes and show the cached list instantly, but always refetch the cart and stock levels when the screen opens. After the user adds to cart, update the cart badge immediately without waiting for a refetch.

For a related pattern, see realtime features explained, which pushes fresh data instead of waiting for a cache to expire.

Common confusions

  • "Clear your cache" is a symptom, not a fix. If users must clear caches to see updates, the cache rules need changing.
  • A cache is not storage. It can be emptied at any time; the real data must live somewhere permanent.
  • Caching private data in shared caches is a leak. Responses for signed-in users must never be stored by a CDN and served to someone else.

Frequently asked questions

Why do I see the old version of my site after publishing?

Usually the browser kept the old HTML page. A hard refresh fetches the new one. If it keeps happening for visitors, the HTML is being cached too long.

Does caching make data unsafe?

Not by itself. The risk is caching a signed-in user's response somewhere shared. Keep personal responses out of shared caches and let only the user's own device store them.

On this page

  • An everyday example: the carpenter's apron
  • The layers of caching in a web app
  • How long to cache: the hard part
  • Why it matters when building with Startbase
  • Common confusions

Keep reading

More in Glossary
Editorial ink illustration of a hand-cranked music box drum plucking a metal comb, the crank handle in ember orange
GlossaryNovember 22, 2026

What is a game loop?

Every real-time game runs one repeating cycle: read input, update the world, draw it. Here is what that cycle looks like and why it decides how your game feels.

3 min read
Editorial ink illustration of a brass stopwatch beside a small wind-up toy car, the second hand in ember orange
GlossaryNovember 22, 2026

What is delta time?

Delta time is the number that keeps your game the same speed on every screen. Here is how to use it, where it breaks, and how to spot a game that forgot it.

3 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.