Implement extension registration from an extension.json file
[mediawiki.git] / includes / objectcache / APCBagOStuff.php
blobd879ca8416ce220a9154e856aead848d5c95aebb
1 <?php
2 /**
3 * Object caching using PHP's APC accelerator.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Cache
24 /**
25 * This is a wrapper for APC's shared memory functions
27 * @ingroup Cache
29 class APCBagOStuff extends BagOStuff {
30 /**
31 * @param string $key
32 * @param int $casToken [optional]
33 * @return mixed
35 public function get( $key, &$casToken = null ) {
36 $val = apc_fetch( $key );
38 $casToken = $val;
40 if ( is_string( $val ) ) {
41 if ( $this->isInteger( $val ) ) {
42 $val = intval( $val );
43 } else {
44 $val = unserialize( $val );
48 return $val;
51 /**
52 * @param string $key
53 * @param mixed $value
54 * @param int $exptime
55 * @return bool
57 public function set( $key, $value, $exptime = 0 ) {
58 if ( !$this->isInteger( $value ) ) {
59 $value = serialize( $value );
62 apc_store( $key, $value, $exptime );
64 return true;
67 /**
68 * @param mixed $casToken
69 * @param string $key
70 * @param mixed $value
71 * @param int $exptime
72 * @return bool
73 * @throws MWException
75 public function cas( $casToken, $key, $value, $exptime = 0 ) {
76 // APC's CAS functions only work on integers
77 throw new MWException( "CAS is not implemented in " . __CLASS__ );
80 /**
81 * @param string $key
82 * @param int $time
83 * @return bool
85 public function delete( $key, $time = 0 ) {
86 apc_delete( $key );
88 return true;
91 /**
92 * @param string $key
93 * @param Closure $callback Callback method to be executed
94 * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
95 * @param int $attempts The amount of times to attempt a merge in case of failure
96 * @return bool Success
98 public function merge( $key, Closure $callback, $exptime = 0, $attempts = 10 ) {
99 return $this->mergeViaLock( $key, $callback, $exptime, $attempts );
102 public function incr( $key, $value = 1 ) {
103 return apc_inc( $key, $value );
106 public function decr( $key, $value = 1 ) {
107 return apc_dec( $key, $value );