MySQL Query Cache (Deprecated)
Also Known As
MySQL query cache removed
query_cache_size MySQL 8
MySQL caching
TL;DR
A server-side cache for SELECT results removed in MySQL 8.0 — it caused severe scalability issues under concurrent writes.
Explanation
MySQL's built-in query cache stored SELECT results and invalidated the entire table's cached results on any write. Under write-heavy workloads it became a contention point — every INSERT/UPDATE/DELETE invalidated potentially thousands of cached queries. It was deprecated in MySQL 5.7.20 and removed in 8.0. Modern alternatives are application-level caches (Redis, Memcached) which give control over cache keys, TTLs, and invalidation logic.
Common Misconception
✗ Enabling MySQL query cache improves performance. On write-heavy workloads, the global mutex on query cache invalidation actually degrades performance significantly.
Why It Matters
Developers who learned MySQL pre-8 sometimes wonder why query_cache_size is no longer available. Application-level caching with Redis provides better control without the write-contention problem.
Common Mistakes
- Expecting query_cache_size to exist in MySQL 8 — it was fully removed.
- Relying on implicit database-level caching instead of explicit application caching.
- Using SELECT SQL_CACHE in queries targeting MySQL 8 — silently ignored.
Avoid When
- Do not set query_cache_size in MySQL 8 config — it causes startup errors as the option was fully removed.
- Do not rely on database-level caching — application-level caching is more predictable and scalable.
When To Use
- Implement application-level caching with Redis or Memcached — gives full control over cache keys and TTLs.
Code Examples
✗ Vulnerable
-- MySQL 8: query_cache_size no longer exists
-- query_cache_size = 64M -- This config option causes startup error in MySQL 8
✓ Fixed
// Application-level caching with Redis (preferred)
$cacheKey = 'user:' . $userId;
$user = $redis->get($cacheKey);
if ($user === null) {
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = ?');
$stmt->execute([$userId]);
$user = $stmt->fetch();
$redis->setex($cacheKey, 300, json_encode($user)); // 5 min TTL
}
return json_decode($user, true);
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
31 Mar 2026
Views
55
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
ChatGPT 1
ChatGPT 31
Perplexity 6
Google 6
Unknown AI 2
SEMrush 2
Ahrefs 1
How they use it
crawler 46
crawler_json 2
Related categories
⚡
DEV INTEL
Tools & Severity
⚙ Fix effort: Medium
⚡ Quick Fix
Implement application-level caching with Redis or Memcached instead of relying on MySQL's removed query cache
📦 Applies To
web
cli
🔗 Prerequisites
🔍 Detection Hints
query_cache_size or SELECT SQL_CACHE in MySQL 8+ environment
Auto-detectable:
✓ Yes
⚠ Related Problems
🤖 AI Agent
Confidence: High
False Positives: Low
✓ Auto-fixable
Fix: Medium
Context: Line