Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

MySQL had a query cache that was deprecated in 5.7 and removed in 8.0. What did it do, why was it removed, and what do you use instead?

The query cache stored the complete result of a SELECT and returned it for any later query with exactly the same text, without running it. It was deprecated in 5.7 and removed in 8.0 because any write to a table threw away every cached result for that table, and a single global mutex protected the whole cache, so on multi-core servers and write-heavy workloads it often slowed MySQL down; even tiny differences in query text caused misses. Instead we rely on a large InnoDB buffer pool, application caching such as Spring Cache with Caffeine or Redis, read replicas, and proxy-level caching like ProxySQL's, and cache where the application knows when data changes.

Why this question is asked

The MySQL query cache is a good example of an optimization that looked like free speed and turned into a bottleneck as hardware and workloads changed. Interviewers ask about it because the reasons it was removed teach general lessons about caching: invalidation granularity, contention, and where cache knowledge belongs. In this answer, we will see how the query cache worked, why its design scaled badly, what replaced it, and why caching works best in the application.

1How the Query Cache Worked

When the query cache was on, MySQL looked up every incoming SELECT before parsing it. The key was the exact query text, together with things such as the current database and character set. If an identical query had run before and its result was still cached, MySQL sent the stored result back immediately, skipping parsing, optimisation and execution. Otherwise it ran the query and stored the result for next time.

SQL
SET GLOBAL query_cache_size = 64 * 1024 * 1024; -- MySQL 5.7 and older only
SELECT name FROM product WHERE id = 7; -- executed, result stored
SELECT name FROM product WHERE id = 7; -- served from the cache
select name from product where id = 7; -- miss: different text (case)
SELECT name FROM product WHERE id = 7 /* api */; -- miss: different text (comment)
SELECT name FROM product WHERE id = 8; -- miss: different value
UPDATE product SET price = 10 WHERE id = 99; -- every cached result for product is dropped
Step throughA SELECT with the query cache on
  1. Identical text in the cache?
    YesReturn the stored resultNoParse, optimise, execute
  2. Store the resultunder the global query cache lock
  3. Any write to the tableinvalidates all its cached results

3 steps in order. Play them, or step through them one at a time.

Notice how fragile the key was. The cache compared text byte by byte, so a change of case, an extra space, a comment added by a framework, or a different parameter value meant a different entry. Queries using non-deterministic functions such as NOW() or RAND() were never cached at all.

2Why It Scaled So Badly

Invalidation was by table, not by row. An UPDATE that changed one product invalidated every cached result that read from the product table, including thousands of queries about other products. On a table that receives a write every few milliseconds, results were thrown away almost as soon as they were stored, so the cache did the extra work of storing results without serving many of them.

Worse, the whole cache was protected by one global mutex. Every lookup, every store and every invalidation had to take it, so on a server with 32 or 64 cores, threads queued for the lock, visible in the processlist as Waiting for query cache lock. Under load, turning the cache on could reduce throughput. MySQL 5.7.20 deprecated it, and MySQL 8.0 removed it, together with its settings.

3What We Use Instead

The replacements cache at levels where the trade-offs are better. First, the InnoDB buffer pool already keeps hot data and index pages in memory, so a repeated query on a well-sized server reads from RAM even without a result cache; many queries that seemed to need the query cache are fast enough simply with the right indexes and enough buffer pool. Second, read replicas spread read traffic over several servers. Third, a proxy such as ProxySQL can cache results of chosen query patterns for a fixed time, which helps legacy applications we cannot change. Fourth, and most powerful, the application caches what it knows how to invalidate.

Alternatives to the query cache
OptionWhat it cachesFreshness
InnoDB buffer pooldata and index pagesalways current
Read replicasnothing, adds read capacityslight replication lag
ProxySQL query cacheresults of matched queriesfixed TTL per rule
Caffeine in each instancedomain objects, per JVMTTL or eviction on change
Redis shared cachedomain objects, all instancesTTL or explicit invalidation

4Cache Where the Application Knows the Rules

The deeper lesson is that the database cannot know which cached results are still correct, except by throwing away everything for a table. The application can. It knows that a product's details change only when an admin edits them, that a price list is published once a day, and which key a change affects. So it can cache the product with key product:7, invalidate exactly that key when product 7 changes, and give data that may be slightly stale a sensible time to live.

Java
@Service
class ProductService {
@Cacheable(cacheNames = "product", key = "#id")
public ProductView find(long id) { return repository.findView(id); } // first call: query, then cached
@CacheEvict(cacheNames = "product", key = "#cmd.id")
public void update(UpdateProduct cmd) { ... } // evicts only product 7
}
// spring.cache.type=caffeine
// spring.cache.caffeine.spec=maximumSize=50000,expireAfterWrite=10m

Notice how the invalidation is precise: changing product 7 evicts one entry, while every other product stays cached. That is the property the query cache never had.

5Follow-up questions

Is it worth using ProxySQL's query cache?

It is useful as a bridge for applications we cannot change, for a few heavy read queries that can tolerate staleness. Because invalidation is only by TTL, it is not a good fit for data that must be fresh, and it should be enabled for specific query rules rather than for all traffic.

Why not just make the buffer pool as big as the data?

Often that is the right first step for read performance, since it removes disk reads. But it does not remove the CPU cost of executing a heavy query again and again, which is where result caching in the application still helps.

What should a Spring Boot service use, Caffeine or Redis?

Caffeine for data each instance can cache on its own with short TTLs, because it is in-process and fastest. Redis when instances must share cached data or invalidation, or when the cache must survive restarts. Many services use both: Caffeine in front of Redis.

6Conclusion

In this answer, we saw that the query cache returned stored results for byte-identical SELECT texts, but invalidated everything for a table on any write and serialised all access behind a global mutex, so it scaled badly on multi-core servers and write-heavy workloads and missed on tiny text differences. It was deprecated in 5.7 and removed in 8.0. Today we rely on a well-sized buffer pool, read replicas, proxy caching like ProxySQL for specific cases, and above all application caches such as Spring Cache with Caffeine or Redis, where the application knows exactly what to invalidate.

What to say in the interviewAbout 80 seconds aloud

Open with

The query cache stored the full result set of a SELECT, keyed by the exact query text, and when the same text came in again it returned the stored result without parsing or executing anything.

Then, if they want more

It sounds great, but it had three problems. First, invalidation was per table: any write to a table threw away every cached result that used that table, so on tables with frequent writes the cache mostly stored results that were discarded before being reused.

Second, the whole cache was protected by a single global mutex, so on servers with many cores threads queued on it, and turning it on could actually lower throughput. Third, the key was the byte-exact text, so a different case, whitespace, a comment or another parameter value was a miss.

That is why it was deprecated in 5.7 and removed in 8.0. Instead, I rely on a big enough InnoDB buffer pool so hot data is in memory, read replicas for read capacity, and for legacy apps sometimes ProxySQL's TTL-based query cache.

Mainly, though, I cache in the application, with Spring Cache over Caffeine or Redis, because the application knows the invalidation rules: it can evict exactly product 7 when product 7 changes, instead of the database throwing away the whole table's results.

About this answer

Last updated
12 November 2026
Versions it names
MySQL 5.7, MySQL 8.0
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
MySQL reference manual
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "MySQL had a query cache that was deprecated in 5.7 and removed in 8.0. What did it do...": https://scrivio-interview-library.netlify.app/databases/mysql/f68451e199/