MySQL stores every SQL text and results of the same in memory. When identical SQL text executes again that time MySQL retrieves data from CACHE and provides output. Indeed memory scan is faster than a disk scan.
This CACHE called QUERY CACHE.
For enabling Query Cache in MySQL.
Modify my.cnf with the following parameters.
Set query_cache_type = 0 means it is disabled
Set query_cache_type = 1 means it is enabled
Set query_cache_type = 2 means it is enabled but works on demand
Another parameter is query_cache_size. This parameter stands for the total size of the Query Cache.
for better performance, we can set it to 25MB. Modify this parameter in my.cnf and put bytes.
Thanks and regards,