Skip to content
IT glossary
BackendUpdated December 3, 2026

Cache

Кэш

A cache keeps previously fetched data or computed results handy so later requests can reuse them instead of doing the same work again.

Also known as: кеширование, caching

What a cache does

Suppose a storefront builds its list of popular products by querying several database tables. If the list only needs to be refreshed every minute, the backend can store the result and serve it repeatedly. That trades some freshness for faster responses and less database work. In this setup, the cache is not the source of truth: if it loses an entry, the service can rebuild it from the database.

The read path: hits and misses

With cache-aside, application code checks the cache before calling the underlying data source. Finding a usable entry is a cache hit. If the entry is absent or expired, that's a cache miss: the application fetches the data, stores a copy, and returns the result.

A time to live (TTL) determines when an entry expires. Choose it based on how long callers can reasonably see old data, not just how often you want to query the database. Expiration is different from eviction: a full cache may drop an entry before its TTL runs out. One common eviction policy, least recently used (LRU), makes room by dropping the entry that was accessed least recently.

Example: caching a storefront response

key = "popular-products:GB:en"
result = cache.get(key)
if result is MISSING:
    result = build_popular_products(market="GB", language="en")
    cache.set(key, result, ttl=60)
return result

The market and language belong in the key because they change the result. Leaving either out could return a perfectly valid response meant for a different request. Check for a missing entry explicitly: an empty product list can be a valid result worth caching.

Where caching helps and what can go wrong

An in-process cache is fast to access, but each service instance has its own copy. A shared cache such as Redis gives instances access to the same entries at the cost of a network round trip and another service to operate. Both can be useful for frequently repeated reads or expensive computations. If requests rarely reuse keys, the lookup and storage costs may outweigh the savings.

A TTL doesn't tell the cache when the underlying data changes. If old values are a problem, the application can invalidate the relevant key after a database update commits. Deleting the key is useful but doesn't guarantee consistency: a concurrent reader may have fetched the old value and write it into the cache after the deletion. Also plan for what happens when a popular entry expires. If hundreds of requests try to rebuild it at once, the data source can be overwhelmed. Request coalescing lets one request do the work while the others wait for its result.

What interviewers look for

In a system design interview, be ready to explain what you'd cache, how you'd construct the key, and how stale the result can be. Walk through an update and a cache outage, not just a hit. Track hit rate alongside end-to-end latency and database load: even a high hit rate can hide a burst of costly misses.