8.4.5 Pattern based caching

An application has three options for telling PECL/mysqlnd_qc
whether a particular statement shall be used. The most basic
approach is to cache all statements by setting
mysqlnd_qc.cache_by_default = 1. This approach
is often of little practical value. But it enables users to make
a quick estimation about the maximum performance gains from
caching. An application designed to use a cache may be able to
prefix selected statements with the appropriate SQL hints.
However, altering an applications source code may not always be
possible or desired, for example, to avoid problems with
software updates. Therefore, PECL/mysqlnd_qc allows setting a
callback which decides if a query is to be cached.

The callback is installed with the
mysqlnd_qc_set_is_select
function. The callback is given the statement string of every
statement inspected by the plugin. Then, the callback can decide
whether to cache the function. The callback is supposed to
return FALSE if the statement shall not be
cached. A return value of TRUE makes the
plugin try to add the statement into the cache. The cache entry
will be given the default TTL
(
mysqlnd_qc.ttl). If the callback returns a
numerical value it is used as the TTL instead of the global
default.