SpecialLinkSearch: clean up munged query variable handling
[mediawiki.git] / includes / objectcache / APCBagOStuff.php
blobafc0f0acb8a0482bb4d78b517d4489aead438dd6
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 protected 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 * @return bool
84 public function delete( $key ) {
85 apc_delete( $key );
87 return true;
90 /**
91 * @param string $key
92 * @param callable $callback Callback method to be executed
93 * @param int $exptime Either an interval in seconds or a unix timestamp for expiry
94 * @param int $attempts The amount of times to attempt a merge in case of failure
95 * @return bool Success
97 public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
98 return $this->mergeViaLock( $key, $callback, $exptime, $attempts );
101 public function incr( $key, $value = 1 ) {
102 return apc_inc( $key, $value );
105 public function decr( $key, $value = 1 ) {
106 return apc_dec( $key, $value );