| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\ApcuException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Retrieves cached information and meta-data from APC's data store. |
| 9 |
* |
| 10 |
* @param bool $limited If limited is TRUE, the |
| 11 |
* return value will exclude the individual list of cache entries. This |
| 12 |
* is useful when trying to optimize calls for statistics gathering. |
| 13 |
* @return array Array of cached data (and meta-data) |
| 14 |
* @throws ApcuException |
| 15 |
* |
| 16 |
*/ |
| 17 |
function apcu_cache_info(bool $limited = false): array |
| 18 |
{ |
| 19 |
error_clear_last(); |
| 20 |
$result = \apcu_cache_info($limited); |
| 21 |
if ($result === false) { |
| 22 |
throw ApcuException::createFromPhpError(); |
| 23 |
} |
| 24 |
return $result; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
/** |
| 29 |
* apcu_cas updates an already existing integer value if the |
| 30 |
* old parameter matches the currently stored value |
| 31 |
* with the value of the new parameter. |
| 32 |
* |
| 33 |
* @param string $key The key of the value being updated. |
| 34 |
* @param int $old The old value (the value currently stored). |
| 35 |
* @param int $new The new value to update to. |
| 36 |
* @throws ApcuException |
| 37 |
* |
| 38 |
*/ |
| 39 |
function apcu_cas(string $key, int $old, int $new): void |
| 40 |
{ |
| 41 |
error_clear_last(); |
| 42 |
$result = \apcu_cas($key, $old, $new); |
| 43 |
if ($result === false) { |
| 44 |
throw ApcuException::createFromPhpError(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* Decreases a stored integer value. |
| 51 |
* |
| 52 |
* @param string $key The key of the value being decreased. |
| 53 |
* @param int $step The step, or value to decrease. |
| 54 |
* @param bool|null $success Optionally pass the success or fail boolean value to |
| 55 |
* this referenced variable. |
| 56 |
* @param int $ttl TTL to use if the operation inserts a new value (rather than decrementing an existing one). |
| 57 |
* @return int Returns the current value of key's value on success |
| 58 |
* @throws ApcuException |
| 59 |
* |
| 60 |
*/ |
| 61 |
function apcu_dec(string $key, int $step = 1, ?bool &$success = null, int $ttl = 0): int |
| 62 |
{ |
| 63 |
error_clear_last(); |
| 64 |
$result = \apcu_dec($key, $step, $success, $ttl); |
| 65 |
if ($result === false) { |
| 66 |
throw ApcuException::createFromPhpError(); |
| 67 |
} |
| 68 |
return $result; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
/** |
| 73 |
* Increases a stored number. |
| 74 |
* |
| 75 |
* @param string $key The key of the value being increased. |
| 76 |
* @param int $step The step, or value to increase. |
| 77 |
* @param bool|null $success Optionally pass the success or fail boolean value to |
| 78 |
* this referenced variable. |
| 79 |
* @param int $ttl TTL to use if the operation inserts a new value (rather than incrementing an existing one). |
| 80 |
* @return int Returns the current value of key's value on success |
| 81 |
* @throws ApcuException |
| 82 |
* |
| 83 |
*/ |
| 84 |
function apcu_inc(string $key, int $step = 1, ?bool &$success = null, int $ttl = 0): int |
| 85 |
{ |
| 86 |
error_clear_last(); |
| 87 |
$result = \apcu_inc($key, $step, $success, $ttl); |
| 88 |
if ($result === false) { |
| 89 |
throw ApcuException::createFromPhpError(); |
| 90 |
} |
| 91 |
return $result; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
/** |
| 96 |
* Retrieves APCu Shared Memory Allocation information. |
| 97 |
* |
| 98 |
* @param bool $limited When set to FALSE (default) apcu_sma_info will |
| 99 |
* return a detailed information about each segment. |
| 100 |
* @return array Array of Shared Memory Allocation data; FALSE on failure. |
| 101 |
* @throws ApcuException |
| 102 |
* |
| 103 |
*/ |
| 104 |
function apcu_sma_info(bool $limited = false): array |
| 105 |
{ |
| 106 |
error_clear_last(); |
| 107 |
$result = \apcu_sma_info($limited); |
| 108 |
if ($result === false) { |
| 109 |
throw ApcuException::createFromPhpError(); |
| 110 |
} |
| 111 |
return $result; |
| 112 |
} |
| 113 |
|