What is a cache and why can it speed up an application so much?

Published on 2026-10-20 by frfrand

Qué es una caché, cómo funcionan hits, misses, TTL e invalidación y cuándo ayuda de verdad a una web.

What is a cache and why can it speed up an application so much?

A cache is a place where we temporarily store results that we will probably need again. It can speed up a website because it avoids repeating queries, calculations, and downloads every time someone asks for the same information.

It's not magic. If your application takes two seconds to calculate a list of products and fifty people request exactly the same list, it might not make sense to do the same work fifty times.

The coffee shop example

Imagine a coffee shop where every customer asks for the menu. The waiter could go down to the storage room, find the original design, and print a new copy for each table. But the reasonable thing is to have several menus ready.

A cache does something similar. It keeps a copy of certain information to respond faster to future requests.

The problem starts when the menu changes: if you keep old menus, you could show prices that are no longer correct. That is the least fun part of caches: invalidating them properly.

Hit, miss, and TTL: three words you will encounter

A cache hit occurs when the requested information is in the cache and can still be used. A cache miss occurs when it is not available or is no longer valid, so the original source must be consulted.

The TTL, or time to live, establishes for how long an entry can be considered valid according to a certain policy.

For example, you could store for five minutes the result of a public categories list. If someone queries it again before it expires, the application can respond using the copy. But a bank account balance requires much more careful handling.

TTL is a tool, not a license to display incorrect data.

Where can caches be?

In the browser: images, fonts, and certain files from a website can be reused without being fully downloaded every time.

In a CDN: copies of resources can be delivered from geographically distributed nodes, close to visitors.

In the application: calculation results or queries can be stored in local memory or in a shared service like Redis.

In the database: different engines keep structures and pages in memory to reduce disk accesses.

These layers do not all work the same way. Nor is it advisable to activate them without knowing what problem you are solving.

How is a cache implemented in an API?

Imagine an endpoint returns featured products. First you check if there is a valid result with a key like productos:destacados. If you find it, you return it. If not, you query the database, prepare the response, and store the result for a limited time.

The process seems simple until two hundred requests arrive just as the same key expires: they could all try to recalculate at the same time. That phenomenon can overload the origin. For demanding cases there are locking strategies, early renewal, or staggered expirations.

You also shouldn't use the same key for responses that depend on each person's permissions. A bad cache can show private data to someone who shouldn't see it.

What does invalidating the cache mean?

It means marking or deleting copies so that the next requests get new data.

You can do it by time, after a specific event, or through a different version of the key. For example, when updating a product's price you might need to invalidate the catalog cache.

One of the most annoying bugs is the one where the administrator sees the new price but visitors keep seeing the previous one. Many times the database isn't failing: someone forgot how the copies are updated.

Does a cache always improve performance?

No. If a query already takes one millisecond, saving and retrieving a copy on another server can add complexity without a real gain. It also consumes memory and forces you to solve consistency, permissions, and cache service failures.

First measure: which operation takes long?, how many times is it repeated?, how long can the information age?, what happens if the cache is lost? Only then choose the strategy.

Where does ArduMaker fit in?

ArduMaker allows you to manage applications and services such as Redis in VPS environments. An application deployed there can use Redis to store temporary results, as long as keys, expirations, and permissions are well designed. Redis is also used for other purposes, so Redis should not be confused with the general concept of caching.

To remember: a cache trades repeated work for temporary storage. It works very well when you know what information can be reused and when it must stop being valid.

Sources: HTTP Caching on MDN · Redis Documentation · Article about Redis on ArduMaker.

What is a cache and why can it speed up an application so much?
  • caché
  • rendimiento
  • backend

Keep reading

All articles · VPS plans