Is there any method to find out if an executed query is retrieved from MySQL query cache?
Of course… there are a lot of methods to count the number of cached queries on general level (SHOW STATUS LIKE '%qcache%' etc), but I want to know specifically if the current executed query is loaded from MySQL cache.
For example, in PHP the function mysql_insert_id(); returns the last inserted ID in a separate query.
In that direction, it would be a beauty to call a metadata function like mysql_is_query_from_cache($previous_query); to verify that the previous query results are actually retrieved from MySQL query cache
Any ideas on this?
For MySQL 5.0 and higher you can use SHOW PROFILES to get a list of recent query IDs and then SHOW PROFILE FOR QUERY %id_here% to see if there was a reference to cached data.
This is explained in more details at http://www.dbasquare.com/2012/04/03/was-a-query-served-from-mysql-query-cache/ along with some other ways around.