MediaWiki  master
APCUBagOStuff.php
Go to the documentation of this file.
1 <?php
36 class APCUBagOStuff extends BagOStuff {
39 
45  const KEY_SUFFIX = ':4';
46 
47  public function __construct( array $params = [] ) {
48  parent::__construct( $params );
49  // The extension serializer is still buggy, unlike "php" and "igbinary"
50  $this->nativeSerialize = ( ini_get( 'apc.serializer' ) !== 'default' );
51  }
52 
53  protected function doGet( $key, $flags = 0, &$casToken = null ) {
54  $casToken = null;
55 
56  $blob = apcu_fetch( $key . self::KEY_SUFFIX );
57  $value = $this->unserialize( $blob );
58  if ( $value !== false ) {
59  $casToken = $blob; // don't bother hashing this
60  }
61 
62  return $value;
63  }
64 
65  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
66  return apcu_store(
67  $key . self::KEY_SUFFIX,
68  $this->serialize( $value ),
69  $exptime
70  );
71  }
72 
73  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
74  return apcu_add(
75  $key . self::KEY_SUFFIX,
76  $this->serialize( $value ),
77  $exptime
78  );
79  }
80 
81  public function delete( $key, $flags = 0 ) {
82  apcu_delete( $key . self::KEY_SUFFIX );
83 
84  return true;
85  }
86 
87  public function incr( $key, $value = 1 ) {
88  // https://github.com/krakjoe/apcu/issues/166
89  if ( apcu_exists( $key . self::KEY_SUFFIX ) ) {
90  return apcu_inc( $key . self::KEY_SUFFIX, $value );
91  } else {
92  return false;
93  }
94  }
95 
96  public function decr( $key, $value = 1 ) {
97  // https://github.com/krakjoe/apcu/issues/166
98  if ( apcu_exists( $key . self::KEY_SUFFIX ) ) {
99  return apcu_dec( $key . self::KEY_SUFFIX, $value );
100  } else {
101  return false;
102  }
103  }
104 
105  protected function serialize( $value ) {
106  if ( $this->nativeSerialize ) {
107  return $value;
108  }
109 
110  return $this->isInteger( $value ) ? (int)$value : serialize( $value );
111  }
112 
113  protected function unserialize( $value ) {
114  if ( $this->nativeSerialize ) {
115  return $value;
116  }
117 
118  return $this->isInteger( $value ) ? (int)$value : unserialize( $value );
119  }
120 }
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$value
This is a wrapper for APCU&#39;s shared memory functions.
unserialize( $value)
__construct(array $params=[])
add( $key, $value, $exptime=0, $flags=0)
bool $nativeSerialize
Whether to trust the APC implementation to serialization.
doGet( $key, $flags=0, &$casToken=null)
$params
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
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
incr( $key, $value=1)
decr( $key, $value=1)
serialize( $value)
isInteger( $value)
Check if a value is an integer.
Definition: BagOStuff.php:734