Cache
Definition
A cache is a temporary high-speed storage layer that keeps frequently accessed data closer to the user or application to reduce latency, improve performance, and decrease load on the original source (database, server, or API).
What Problem It Solves
- Faster response times
- Reduced database/API requests
- Lower server load
- Better scalability and user experience
What Happens If Not Used
Every request must fetch data from the original source, causing slower performance, higher resource usage, and increased costs.
Easy Wording
Cache is a shortcut copy of data stored temporarily so it can be retrieved quickly instead of being recreated or fetched again.
Layman Example
A teacher keeps frequently used attendance sheets on her desk instead of going to the filing cabinet every time. The desk copy is the cache.
Technical Example
A product page requests product details:
- Check cache (Redis/Browser/CDN).
- If found (cache hit), return data immediately.
- If not found (cache miss), fetch from database/server, return it, and store it in cache for future requests.
Common Types of Cache
Browser Cache
- Stores images, CSS, JavaScript, fonts, and other static files on the user's device.
- Reduces repeated downloads and speeds up page loading.
Redis Cache
- Stores database query results, user sessions, API responses, and frequently accessed application data in memory.
- Reduces database load and improves application performance.
CDN Cache
- Stores static content on distributed servers located in different geographic regions.
- Delivers content from the server closest to the user, reducing latency and improving loading speed.
Key Terms: Cache, Cache Hit, Cache Miss, TTL (Time To Live), In-Memory Storage, Latency, Performance, Redis, Browser Cache, CDN Cache, Temporary Storage.