Using sql_cache in MySQL query


When I learned MySQL, I was recommended to use the sql_cache expression after the SELECT , something like this:

"SELECT sql_cache * FROM tabela..."

Since then I started using this in my codes, but it was never very clear to me what this is for, if it has to do with caching, speeds up the query, anyway. Also I never noticed any difference hiding such expression from the query. I use Classic ASP.

What is the function of using sql_cache ? Is it okay to use this or doesn't it make any difference?


Yes it does have an impact on the query if it is run again, and can precede with two types the ones that cache the query and a second one that does not and are used infrequently.

But pay attention to the version of MySql as from version 5.7 it will be discontinued, and in version 8 it will be removed.


Generally, you shouldn't have to use this at all. SQL_CACHE is only necessary if queries are not cached by default, and they are not in the application's default configuration, as in the case of wordpress.


It's useful if you know that a specific query won't be used again in the near future, especially if the result set is large. The goal is to avoid caching the cache with results that won't be needed again.

Applications tend to provide cache internally as wordpress works with specific plugins for this purpose, for this reason mysql tends to remove this function.

It is worth mentioning if in your case your application in asp classico has this cache storage.

Here's an explanation in the MySql documentation, I use both methods and the difference is noticeable in processing.

Scroll to Top