MediaWiki  master
MemcachedPhpBagOStuff.php
Go to the documentation of this file.
1 <?php
31  protected $client;
32 
43  function __construct( $params ) {
44  parent::__construct( $params );
45 
46  // Default class-specific parameters
47  $params += [
48  'compress_threshold' => 1500,
49  'connect_timeout' => 0.5
50  ];
51 
52  $this->client = new MemcachedClient( $params );
53  $this->client->set_servers( $params['servers'] );
54  }
55 
56  public function setDebug( $enabled ) {
57  parent::debug( $enabled );
58  $this->client->set_debug( $enabled );
59  }
60 
61  protected function doGet( $key, $flags = 0, &$casToken = null ) {
62  $casToken = null;
63 
64  return $this->client->get( $this->validateKeyEncoding( $key ), $casToken );
65  }
66 
67  protected function doSet( $key, $value, $exptime = 0, $flags = 0 ) {
68  return $this->client->set(
69  $this->validateKeyEncoding( $key ),
70  $value,
71  $this->fixExpiry( $exptime )
72  );
73  }
74 
75  protected function doDelete( $key, $flags = 0 ) {
76  return $this->client->delete( $this->validateKeyEncoding( $key ) );
77  }
78 
79  public function add( $key, $value, $exptime = 0, $flags = 0 ) {
80  return $this->client->add(
81  $this->validateKeyEncoding( $key ),
82  $value,
83  $this->fixExpiry( $exptime )
84  );
85  }
86 
87  protected function cas( $casToken, $key, $value, $exptime = 0, $flags = 0 ) {
88  return $this->client->cas(
89  $casToken,
90  $this->validateKeyEncoding( $key ),
91  $value,
92  $this->fixExpiry( $exptime )
93  );
94  }
95 
96  public function incr( $key, $value = 1 ) {
97  $n = $this->client->incr( $this->validateKeyEncoding( $key ), $value );
98 
99  return ( $n !== false && $n !== null ) ? $n : false;
100  }
101 
102  public function decr( $key, $value = 1 ) {
103  $n = $this->client->decr( $this->validateKeyEncoding( $key ), $value );
104 
105  return ( $n !== false && $n !== null ) ? $n : false;
106  }
107 
108  protected function doChangeTTL( $key, $exptime, $flags ) {
109  return $this->client->touch(
110  $this->validateKeyEncoding( $key ),
111  $this->fixExpiry( $exptime )
112  );
113  }
114 
115  protected function doGetMulti( array $keys, $flags = 0 ) {
116  foreach ( $keys as $key ) {
117  $this->validateKeyEncoding( $key );
118  }
119 
120  return $this->client->get_multi( $keys );
121  }
122 
123  protected function serialize( $value ) {
124  return is_int( $value ) ? $value : $this->client->serialize( $value );
125  }
126 
127  protected function unserialize( $value ) {
128  return $this->isInteger( $value ) ? (int)$value : $this->client->unserialize( $value );
129  }
130 }
memcached client class implemented using (p)fsockopen()
fixExpiry( $expiry)
TTLs higher than 30 days will be detected as absolute TTLs (UNIX timestamps), and will result in the ...
$value
validateKeyEncoding( $key)
Ensure that a key is safe to use (contains no control characters and no characters above the ASCII ra...
$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:767
doGet( $key, $flags=0, &$casToken=null)
doGetMulti(array $keys, $flags=0)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
doChangeTTL( $key, $exptime, $flags)
doSet( $key, $value, $exptime=0, $flags=0)
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
add( $key, $value, $exptime=0, $flags=0)
Base class for memcached clients.
isInteger( $value)
Check if a value is an integer.
__construct( $params)
Available parameters are:
A wrapper class for the pure-PHP memcached client, exposing a BagOStuff interface.
cas( $casToken, $key, $value, $exptime=0, $flags=0)