Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why Your Database Isn't Slow. Your Cache Is Missing

If you've ever wondered why every backend system you read about has a cache sitting somewhere in the architecture diagram, this is the "why" behind it, explained the way I actually understood it, not the textbook way. The problem: repeated reads that don't need to happen Imagine a database that many users hit to read the exact same piece of data. Not different data, the same data, over and over.…

Repeated reads of the same data from a database can be unnecessary and wasteful. This is because the data has not changed between requests, so the database is performing the same job multiple times. Caching solves this problem by reducing the number of calls to the database, thus decreasing the load on it.

Think of a cache like a front shelf of your bookshelf, filled with the books you read most often. When you want to read a book, you first check the small shelf. If it's there, you grab it instantly. If not, you go to the full bookshelf. Similarly, a cache sits in front of the database and answers requests directly when it can.

However, not everything should be cached. The data should be mostly the same over time and should be asked for repeatedly by users. Examples of data that should be cached include addresses, profiles, and famous posts that aren't often edited. On the other hand, data that's only read once, like one-time passwords, shouldn't be cached.

Caching can sometimes serve outdated information, a problem called staleness. To avoid this, caches use a Time To Live (TTL) - a timer attached to each piece of cached data that says how long it's valid. When the data changes, it should be written to the database first and then updated in the cache.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Is Investing in eCommerce Website Development Actually Worth It?

You can have great products, competitive prices, and plenty of visitors, yet still lose sales because your online store is slow, confusing, difficult to use on mobile, or frustrating at checkout.

  • eCommerce website development costs vary based on design, integrations, features, and maintenance.
  • Improving checkout UX can significantly boost conversion rates and ROI for businesses.

More from Friday 25 September →