Since I knew that the MySQL Query Cache used the literal queries as keys, it made sense that MySQL did not cache queries with certain SQL functions in them, such as this one:
$sql = "select event_id from events where event_dt >= curdate()";
Because MySQL knows that this query run today is not the same query when it is run tomorrow. There are other SQL functions such as
unix_timestamp() that will bypass the query cache. These are listed here.
So I avoid these functions when possible by calculating the value in PHP. For example, I’d rewrite the above query as:
$date = date('Y-m-d'); $sql = "select event_id from events where event_dt >= '$date'";