MediaWiki  master
APCBagOStuff.php
Go to the documentation of this file.
1 <?php
36 class APCBagOStuff 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 = apc_fetch( $key . self::KEY_SUFFIX );
57  $value = $this->nativeSerialize ? $blob : $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  apc_store(
67  $key . self::KEY_SUFFIX,
68  $this->nativeSerialize ? $value : $this->serialize( $value ),
69  $exptime
70  );
71 
72  return true;
73  }
74 
75  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
76  return apc_add(
77  $key . self::KEY_SUFFIX,
78  $this->nativeSerialize ? $value : $this->serialize( $value ),
79  $exptime
80  );
81  }
82 
83  public function delete( $key, $flags = 0 ) {
84  apc_delete( $key . self::KEY_SUFFIX );
85 
86  return true;
87  }
88 
89  public function incr( $key, $value = 1 ) {
90  return apc_inc( $key . self::KEY_SUFFIX, $value );
91  }
92 
93  public function decr( $key, $value = 1 ) {
94  return apc_dec( $key . self::KEY_SUFFIX, $value );
95  }
96 
97  protected function serialize( $value ) {
98  return $this->isInteger( $value ) ? (int)$value : serialize( $value );
99  }
100 
101  protected function unserialize( $value ) {
102  return $this->isInteger( $value ) ? (int)$value : unserialize( $value );
103  }
104 }
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
__construct(array $params=[])
This is a wrapper for APC&#39;s shared memory functions.
incr( $key, $value=1)
$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
add( $key, $value, $exptime=0, $flags=0)
bool $nativeSerialize
Whether to trust the APC implementation to serialization.
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
unserialize( $value)
doGet( $key, $flags=0, &$casToken=null)
isInteger( $value)
Check if a value is an integer.
Definition: BagOStuff.php:734
serialize( $value)
decr( $key, $value=1)