Skip to main content

Command Palette

Search for a command to run...

πŸ—„οΈ Caching Explained Like You're 5

Published
β€’2 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

Keeping snacks on your desk

Day 12 of 149

πŸ‘‰ Full deep-dive with code examples


The Snack Drawer

You're working. You get hungry.

Without snack drawer:

  • Walk to kitchen (far!)
  • Open fridge
  • Get snack
  • Walk back
  • Takes a while 😫

With snack drawer:

  • Open desk drawer
  • Grab snack
  • Takes a few seconds! πŸŽ‰

The snack drawer is your cache!


In Computers

Your app needs user data.

Without cache:

  • Ask database (slow!)
  • Database searches millions of records
  • Sends data back
  • Might take noticeably longer 😫

With cache:

  • Check cache (in memory, super fast!)
  • Data is already there
  • Often returns much faster πŸš€

How It Works

First time someone asks for data:

Browser β†’ Server β†’ Database β†’ Data found!
                     ↓
          Store in cache for later
                     ↓
         Return to browser

Next time:

Browser β†’ Server β†’ Check cache β†’ Data found!
         Return immediately (skip database!)

The Catch

What if data changes?

  • You cached "User has 5 friends"
  • User adds a friend
  • Cache still says 5 friends!

Solution: Caches expire after some time, or get cleared when data changes.


In One Sentence

Caching stores frequently-used data closer to you so you don't have to fetch it from far away every time.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

More from this blog

esreekarreddy

132 posts