What is query caching in MySQL?
Answer
MySQL had a built-in query cache that cached the complete result set of SELECT queries. On subsequent identical queries (exact same SQL and database state), MySQL returned cached results without re-executing. However, the query cache was removed in MySQL 8.0 because it was a scalability bottleneck: (1) The cache required a global mutex lock on every write, causing contention on write-heavy workloads; (2) Any write to any table in the query invalidated all cached queries involving that table; (3) Modern hardware with fast SSDs and efficient buffer pools made the query cache less beneficial. Alternatives for caching: (1) Application-level cache: use Redis or Memcached to cache query results in your application code — more control over invalidation logic and expiry; (2) InnoDB Buffer Pool: MySQL's own page cache (default 128MB, should be 70-80% of available RAM for dedicated servers) caches disk pages in memory — properly sizing this is more impactful than query cache; (3) ProxySQL Query Cache — proxy layer that caches query results; (4) Read replicas reduce primary write contention. Always cache at the application layer for production systems.
Previous
What is the difference between VARCHAR and TEXT in MySQL?
Next
What is the difference between COUNT(*), COUNT(1), and COUNT(column)?