← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

MySQL Query Cache (Deprecated)

Database Intermediate
debt(d7/e7/b5/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note a code_pattern (query_cache_size or SELECT SQL_CACHE in MySQL 8+), but the real danger is on write-heavy workloads where the global mutex silently degrades performance without throwing errors. In MySQL 8 the setting is simply ignored or absent, and SELECT SQL_CACHE is silently a no-op — neither the app nor a standard linter flags the problem. Only careful code review, MySQL configuration audits, or runtime performance profiling reveals the issue.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix says to implement application-level caching with Redis or Memcached instead. This is not a one-line swap — it requires identifying all code paths that implicitly relied on the query cache, adding a caching layer (Redis/Memcached), designing cache keys and TTL strategies, and potentially touching many queries and service components across the codebase. This spans multiple files and represents a significant architectural shift in caching strategy.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The applies_to covers both web and cli contexts, meaning any MySQL-backed project can be affected. Developers who learned pre-MySQL 8 carry a mental model of free implicit caching that no longer exists; every performance investigation and new feature must account for the absence of query cache and the need for explicit application-level caching. This is a persistent tax on multiple work streams but doesn't fully define the system's shape.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field states directly: 'Enabling MySQL query cache improves performance' — but on write-heavy workloads it actually degrades performance via the global mutex. Additionally, in MySQL 8 the feature is completely removed and SELECT SQL_CACHE is silently ignored, contradicting the expectation of pre-8 developers who assume it still works. This contradicts behavior from a previous version of the same tool and from how similar caching concepts behave elsewhere, making it a serious trap.

About DEBT scoring →

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);

Added 31 Mar 2026
Views 183
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 2 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S
PetalBot 1
Ahrefs 1
ChatGPT 82 Google 8 PetalBot 8 Perplexity 7 SEMrush 7 Ahrefs 5 Bing 5 Scrapy 4 Claude 3 Unknown AI 2 Applebot 2 Meta AI 1 Qwen 1 Majestic 1 Twitter/X 1 Brave Search 1 Amazonbot 1
crawler 132 crawler_json 7
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Database database A database is an organized collection of data stored electronically, designed so programs can efficiently retrieve, add, update, and delete information.

Nearly every application needs to remember information between sessions. Databases provide the reliable, fast, and organized storage that makes persistent data possible at any scale.

💡 Always use prepared statements with placeholders—never concatenate user input directly into database queries.

Ask Codex about Database →
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
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Medium Context: Line


✓ schema.org compliant