Welcome to Cache Academy
Learn how caching works in system design
Caching is like having a small notepad where you write down information you use often, so you don't have to look it up in a big encyclopedia every time.
In computing, a cache stores frequently accessed data in a faster storage layer so it can be retrieved more quickly than accessing the original source.
Why Do We Need Caching?
Speed
Accessing data from a cache is much faster than from a database or remote API
Reduced Load
Fewer requests to your database means it can handle more important work
Scalability
Systems can handle more users and traffic with effective caching
The Cache
A temporary storage that keeps frequently accessed data ready for quick retrieval. It's typically smaller but much faster than the main storage.
- •Fast access (memory, SSD)
- •Limited capacity
- •Temporary storage
The Database
The main storage system that holds all your data permanently. It's comprehensive but typically slower to access than a cache.
- •Slower access (disk, network)
- •Large capacity
- •Persistent storage
Example of Caching Systems
The Caching Challenge
The key challenge in caching is deciding when and how to move data between the cache and the database. This is where different caching strategies come in.
Questions to Answer:
- ?When should data be added to the cache?
- ?How long should data stay in the cache?
- ?When should the database be updated?
Caching Strategies:
- •Write-Through Cache
- •Write-Back Cache
- •Write-Around Cache
- •Read-Through Cache