42 const KEY_SUFFIX =
':2';
55 if ( isset(
$params[
'nativeSerialize'] ) ) {
56 $this->nativeSerialize =
$params[
'nativeSerialize'];
57 } elseif ( extension_loaded(
'apcu' ) && ini_get(
'apc.serializer' ) ===
'default' ) {
63 $this->logger->warning(
64 'The APCu extension is loaded and the apc.serializer INI setting ' .
65 'is set to "default". This can cause memory corruption! ' .
66 'You should change apc.serializer to "php" instead. ' .
67 'See <https://github.com/krakjoe/apcu/issues/38>.'
69 $this->nativeSerialize =
false;
71 $this->nativeSerialize =
true;
75 protected function doGet( $key, $flags = 0 ) {
77 apc_fetch( $key . self::KEY_SUFFIX )
82 if ( is_string(
$value ) && !$this->nativeSerialize ) {
90 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
92 $key . self::KEY_SUFFIX,
101 if ( !$this->nativeSerialize && !$this->
isInteger( $value ) ) {
107 public function delete( $key ) {
108 apc_delete( $key . self::KEY_SUFFIX );
114 return apc_inc( $key . self::KEY_SUFFIX,
$value );
118 return apc_dec( $key . self::KEY_SUFFIX,
$value );
unserialize( $serialized)
This is a wrapper for APC's shared memory functions.
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
bool $nativeSerialize
If true, trust the APC implementation to serialize and deserialize objects correctly.
__construct(array $params=[])
Available parameters are:
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
interface is intended to be more or less compatible with the PHP memcached client.
isInteger( $value)
Check if a value is an integer.