MediaWiki  1.34.0
APCUBagOStuff.php
Go to the documentation of this file.
1 <?php
39 
45  const KEY_SUFFIX = ':4';
46 
47  public function __construct( array $params = [] ) {
48  $params['segmentationSize'] = $params['segmentationSize'] ?? INF;
49  parent::__construct( $params );
50  // The extension serializer is still buggy, unlike "php" and "igbinary"
51  $this->nativeSerialize = ( ini_get( 'apc.serializer' ) !== 'default' );
52  }
53 
54  protected function doGet( $key, $flags = 0, &$casToken = null ) {
55  $casToken = null;
56 
57  $blob = apcu_fetch( $key . self::KEY_SUFFIX );
58  $value = $this->nativeSerialize ? $blob : $this->unserialize( $blob );
59  if ( $value !== false ) {
60  $casToken = $blob; // don't bother hashing this
61  }
62 
63  return $value;
64  }
65 
66  protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
67  return apcu_store(
68  $key . self::KEY_SUFFIX,
69  $this->nativeSerialize ? $value : $this->serialize( $value ),
70  $exptime
71  );
72  }
73 
74  protected function doAdd( $key, $value, $exptime = 0, $flags = 0 ) {
75  return apcu_add(
76  $key . self::KEY_SUFFIX,
77  $this->nativeSerialize ? $value : $this->serialize( $value ),
78  $exptime
79  );
80  }
81 
82  protected function doDelete( $key, $flags = 0 ) {
83  apcu_delete( $key . self::KEY_SUFFIX );
84 
85  return true;
86  }
87 
88  public function incr( $key, $value = 1, $flags = 0 ) {
89  // https://github.com/krakjoe/apcu/issues/166
90  if ( apcu_exists( $key . self::KEY_SUFFIX ) ) {
91  return apcu_inc( $key . self::KEY_SUFFIX, $value );
92  } else {
93  return false;
94  }
95  }
96 
97  public function decr( $key, $value = 1, $flags = 0 ) {
98  // https://github.com/krakjoe/apcu/issues/166
99  if ( apcu_exists( $key . self::KEY_SUFFIX ) ) {
100  return apcu_dec( $key . self::KEY_SUFFIX, $value );
101  } else {
102  return false;
103  }
104  }
105 }
APCUBagOStuff\doAdd
doAdd( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
Definition: APCUBagOStuff.php:74
MediumSpecificBagOStuff\serialize
serialize( $value)
Definition: MediumSpecificBagOStuff.php:941
APCUBagOStuff\doGet
doGet( $key, $flags=0, &$casToken=null)
Definition: APCUBagOStuff.php:54
APCUBagOStuff\doDelete
doDelete( $key, $flags=0)
Delete an item.
Definition: APCUBagOStuff.php:82
$blob
$blob
Definition: testCompression.php:65
MediumSpecificBagOStuff
Storage medium specific cache for storing items (e.g.
Definition: MediumSpecificBagOStuff.php:34
APCUBagOStuff\decr
decr( $key, $value=1, $flags=0)
Decrease stored value of $key by $value while preserving its TTL.
Definition: APCUBagOStuff.php:97
APCUBagOStuff\__construct
__construct(array $params=[])
Definition: APCUBagOStuff.php:47
APCUBagOStuff\$nativeSerialize
bool $nativeSerialize
Whether to trust the APC implementation to serialization.
Definition: APCUBagOStuff.php:38
APCUBagOStuff
This is a wrapper for APCU's shared memory functions.
Definition: APCUBagOStuff.php:36
MediumSpecificBagOStuff\unserialize
unserialize( $value)
Definition: MediumSpecificBagOStuff.php:950
APCUBagOStuff\incr
incr( $key, $value=1, $flags=0)
Increase stored value of $key by $value while preserving its TTL.
Definition: APCUBagOStuff.php:88
APCUBagOStuff\doSet
doSet( $key, $value, $exptime=0, $flags=0)
Set an item.
Definition: APCUBagOStuff.php:66