Oracle 5.0 Reference Manual page 2681

Table of Contents

Advertisement

Mysqlnd query result cache plugin (mysqlnd_qc)
• not eligible for caching and not cached:
• eligible for caching but uncached:
• eligible for caching and cached:
The examples
statement string is prefixed with the
SELECT
to enable caching of the statement. The SQL hint must be given at the very beginning of the statement
string to enable caching.
Example 20.305. Using the
mysqlnd_qc.enable_qc=1
<?php
/* Connect, create and populate test table */
$mysqli = new mysqli("host", "user", "password", "schema", "port", "socket");
$mysqli->query("DROP TABLE IF EXISTS test");
$mysqli->query("CREATE TABLE test(id INT)");
$mysqli->query("INSERT INTO test(id) VALUES (1), (2)");
/* Will be cached because of the SQL hint */
$start = microtime(true);
$res
= $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1");
var_dump($res->fetch_assoc());
$res->free();
printf("Total time uncached query: %.6fs\n", microtime(true) - $start);
/* Cache hit */
$start = microtime(true);
$res
= $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1");
var_dump($res->fetch_assoc());
$res->free();
printf("Total time cached query: %.6fs\n", microtime(true) - $start);
?>
The above examples will output something similar to:
array(1) {
["id"]=>
string(1) "1"
}
Total time uncached query: 0.000740s
array(1) {
["id"]=>
string(1) "1"
}
Total time cached query: 0.000098s
If nothing else is configured, as it is the case in the quickstart example, the plugin will use the built-in
storage handler. The
default
Depending on the PHP deployment model, a PHP process may serve one or more web requests.
Please, consult the web server manual for details. Details make no difference for the examples given in
the quickstart.
The query cache plugin will cache all queries regardless if the query string begins with the SQL hint
which enables caching or not, if the PHP configuration directive
SHOW ENGINES
SELECT id FROM test
/*qc=on*/SELECT id FROM test
MYSQLND_QC_ENABLE_SWITCH
storage handler uses process memory to hold a cache entry.
default
2661
MYSQLND_QC_ENABLE_SWITCH
SQL hint
mysqlnd_qc.cache_by_default
SQL hint
is

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents