I recently encountered a similar problem, and here's how I solved it ...
Step 1: Add the .user.ini file to the .user.ini directory of your project (if you do not already have one) and the following directives to the file to enable the mysqlnd_qc plugin and set the TTL for the cache:
; Enables MySQL query caching by PHP mysqlnd_qc.enable_qc = 1 ; Set a default TTL for the caching in seconds mysqlnd_qc.ttl = 30
Step 2: Add an SQL prompt before any query that you want to cache using mysqlnd_qc.
Here is a tip that should be added to the request:
"/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" .
Here is a usage example:
$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1");
That should do it! You can also cache all queries using the mysqlnd_qc.cache_no_table = 1 directive.
All this comes from the PHP documentation, here: http://php.net/manual/en/mysqlnd-qc.quickstart.caching.php
Hope this helps!
Ian N.
source share