Oracle 5.0 Reference Manual page 2685

Table of Contents

Advertisement

Mysqlnd query result cache plugin (mysqlnd_qc)
the query string contains a hint for setting a different TTL. The
cache entries expire after
The example sets
mysqlnd_qc.ttl=3
second it updates a database table record to hold the current time and executes a
to fetch the record from the database. The
is prefixed with the SQL hint enabling caching. The output verifies that the query results are taken from
the cache for the duration of three seconds before they are refreshed.
Example 20.309. Setting the TTL with the
mysqlnd_qc.enable_qc=1
mysqlnd_qc.ttl=3
<?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 VARCHAR(255))");
for ($i = 0; $i < 7; $i++) {
/* update DB row
if (!$mysqli->query("DELETE FROM test") ||
!$mysqli->query("INSERT INTO test(id) VALUES (NOW())"))
/* Of course, a real-life script should do better error handling */
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
/* select latest row but cache results */
$query
= "/*" . MYSQLND_QC_ENABLE_SWITCH . "*/";
$query .= "SELECT id AS _time FROM test";
if (!($res = $mysqli->query($query)) ||
!($row = $res->fetch_assoc()))
{
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
$res->free();
printf("Wall time %s - DB row time %s\n", date("H:i:s"), $row['_time']);
/* pause one second */
sleep(1);
}
?>
The above examples will output something similar to:
Wall time 14:55:59 - DB row time 2012-01-11 14:55:59
Wall time 14:56:00 - DB row time 2012-01-11 14:55:59
Wall time 14:56:01 - DB row time 2012-01-11 14:55:59
Wall time 14:56:02 - DB row time 2012-01-11 14:56:02
Wall time 14:56:03 - DB row time 2012-01-11 14:56:02
Wall time 14:56:04 - DB row time 2012-01-11 14:56:02
Wall time 14:56:05 - DB row time 2012-01-11 14:56:05
As can be seen from the example, any
automatically invalidated, if underlying data changes. Applications using the default
strategy must be able to work correctly with stale data.
A user-defined cache storage handler can implement any invalidation strategy to work around this
limitation.
seconds
30
to cache statements for three seconds by default. Every
SELECT
mysqlnd_qc.ttl
*/
based cache can serve stale data. Cache entries are not
TTL
2665
is specified in seconds. By default
TTL
statement is cached for three seconds because it
ini setting
statement
SELECT
invalidation
TTL

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents