MediaWiki  1.33.0
APCUBagOStuff.php
Go to the documentation of this file.
1 <?php
36 class APCUBagOStuff extends BagOStuff {
42  const KEY_SUFFIX = ':3';
43 
44  protected function doGet( $key, $flags = 0, &$casToken = null ) {
45  $casToken = null;
46 
47  $blob = apcu_fetch( $key . self::KEY_SUFFIX );
48  $value = $this->unserialize( $blob );
49  if ( $value !== false ) {
50  $casToken = $blob; // don't bother hashing this
51  }
52 
53  return $value;
54  }
55 
56  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
57  apcu_store(
58  $key . self::KEY_SUFFIX,
59  $this->serialize( $value ),
60  $exptime
61  );
62 
63  return true;
64  }
65 
66  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
67  return apcu_add(
68  $key . self::KEY_SUFFIX,
69  $this->serialize( $value ),
70  $exptime
71  );
72  }
73 
74  public function delete( $key, $flags = 0 ) {
75  apcu_delete( $key . self::KEY_SUFFIX );
76 
77  return true;
78  }
79 
80  public function incr( $key, $value = 1 ) {
86  if ( apcu_exists( $key . self::KEY_SUFFIX ) ) {
87  return apcu_inc( $key . self::KEY_SUFFIX, $value );
88  } else {
89  return false;
90  }
91  }
92 
93  public function decr( $key, $value = 1 ) {
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 
106  protected function serialize( $value ) {
107  return $this->isInteger( $value ) ? (int)$value : serialize( $value );
108  }
109 
110  protected function unserialize( $value ) {
111  return $this->isInteger( $value ) ? (int)$value : unserialize( $value );
112  }
113 }
BagOStuff\isInteger
isInteger( $value)
Check if a value is an integer.
Definition: BagOStuff.php:734
APCUBagOStuff\unserialize
unserialize( $value)
Definition: APCUBagOStuff.php:110
BagOStuff
Class representing a cache/ephemeral data store.
Definition: BagOStuff.php:58
APCUBagOStuff\doGet
doGet( $key, $flags=0, &$casToken=null)
Definition: APCUBagOStuff.php:44
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
APCUBagOStuff\decr
decr( $key, $value=1)
Decrease stored value of $key by $value while preserving its TTL.
Definition: APCUBagOStuff.php:93
APCUBagOStuff\add
add( $key, $value, $exptime=0, $flags=0)
Insert an item if it does not already exist.
Definition: APCUBagOStuff.php:66
$blob
$blob
Definition: testCompression.php:65
APCUBagOStuff\incr
incr( $key, $value=1)
Increase stored value of $key by $value while preserving its TTL.
Definition: APCUBagOStuff.php:80
$value
$value
Definition: styleTest.css.php:49
APCUBagOStuff\serialize
serialize( $value)
Definition: APCUBagOStuff.php:106
APCUBagOStuff
This is a wrapper for APCU's shared memory functions.
Definition: APCUBagOStuff.php:36