A cache stores a reusable result close to its reader. On a cache miss, the service loads the source value and may save a copy for later requests. The database remains the source of truth unless the problem explicitly describes another design. Choose a key that includes every input affecting the result, including tenant or user identity when the result is private.
Cached values become stale. A time to live bounds how long an untouched entry can remain, while invalidation removes or replaces entries after a write. Neither should be assumed to solve every race. A popular key expiring can send many identical requests to the database at once. Request coalescing lets one request reload it while the others wait. Use the supplied freshness tolerance and traffic figures to decide whether caching is useful and safe.