| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\MysqlndQcException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Flush all cache contents. |
| 9 |
* |
| 10 |
* Flushing the cache is a storage handler responsibility. |
| 11 |
* All built-in storage handler but the |
| 12 |
* memcache storage |
| 13 |
* handler support flushing the cache. The |
| 14 |
* memcache |
| 15 |
* storage handler cannot flush its cache contents. |
| 16 |
* |
| 17 |
* User-defined storage handler may or may not support the operation. |
| 18 |
* |
| 19 |
* @throws MysqlndQcException |
| 20 |
* |
| 21 |
*/ |
| 22 |
function mysqlnd_qc_clear_cache(): void |
| 23 |
{ |
| 24 |
error_clear_last(); |
| 25 |
$result = \mysqlnd_qc_clear_cache(); |
| 26 |
if ($result === false) { |
| 27 |
throw MysqlndQcException::createFromPhpError(); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* Installs a callback which decides whether a statement is cached. |
| 34 |
* |
| 35 |
* There are several ways of hinting PELC/mysqlnd_qc to cache a query. |
| 36 |
* By default, PECL/mysqlnd_qc attempts to cache a if caching of all statements |
| 37 |
* is enabled or the query string begins with a certain SQL hint. |
| 38 |
* The plugin internally calls a function named is_select() |
| 39 |
* to find out. This internal function can be replaced with a user-defined callback. |
| 40 |
* Then, the user-defined callback is responsible to decide whether the plugin |
| 41 |
* attempts to cache a statement. Because the internal function is replaced |
| 42 |
* with the callback, the callback gains full control. The callback is free |
| 43 |
* to ignore the configuration setting mysqlnd_qc.cache_by_default |
| 44 |
* and SQL hints. |
| 45 |
* |
| 46 |
* The callback is invoked for every statement inspected by the plugin. |
| 47 |
* It is given the statements string as a parameter. The callback returns |
| 48 |
* FALSE if the statement shall not be cached. It returns TRUE to |
| 49 |
* make the plugin attempt to cache the statements result set, if any. |
| 50 |
* A so-created cache entry is given the default TTL set with the |
| 51 |
* PHP configuration directive mysqlnd_qc.ttl. |
| 52 |
* If a different TTL shall be used, the callback returns a numeric |
| 53 |
* value to be used as the TTL. |
| 54 |
* |
| 55 |
* The internal is_select function is part of the internal |
| 56 |
* cache storage handler interface. Thus, a user-defined storage handler |
| 57 |
* offers the same capabilities. |
| 58 |
* |
| 59 |
* @param string $callback |
| 60 |
* @return mixed Returns TRUE on success. |
| 61 |
* @throws MysqlndQcException |
| 62 |
* |
| 63 |
*/ |
| 64 |
function mysqlnd_qc_set_is_select(string $callback) |
| 65 |
{ |
| 66 |
error_clear_last(); |
| 67 |
$result = \mysqlnd_qc_set_is_select($callback); |
| 68 |
if ($result === false) { |
| 69 |
throw MysqlndQcException::createFromPhpError(); |
| 70 |
} |
| 71 |
return $result; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
/** |
| 76 |
* Sets the storage handler used by the query cache. A list of available |
| 77 |
* storage handler can be obtained from |
| 78 |
* mysqlnd_qc_get_available_handlers. |
| 79 |
* Which storage are available depends on the compile time |
| 80 |
* configuration of the query cache plugin. The |
| 81 |
* default storage handler is always available. |
| 82 |
* All other storage handler must be enabled explicitly when building the |
| 83 |
* extension. |
| 84 |
* |
| 85 |
* @param string $handler Handler can be of type string representing the name of a |
| 86 |
* built-in storage handler or an object of type |
| 87 |
* mysqlnd_qc_handler_default. |
| 88 |
* The names of the built-in storage handler are |
| 89 |
* default, |
| 90 |
* APC, |
| 91 |
* MEMCACHE, |
| 92 |
* sqlite. |
| 93 |
* @throws MysqlndQcException |
| 94 |
* |
| 95 |
*/ |
| 96 |
function mysqlnd_qc_set_storage_handler(string $handler): void |
| 97 |
{ |
| 98 |
error_clear_last(); |
| 99 |
$result = \mysqlnd_qc_set_storage_handler($handler); |
| 100 |
if ($result === false) { |
| 101 |
throw MysqlndQcException::createFromPhpError(); |
| 102 |
} |
| 103 |
} |
| 104 |
|