Allow to set stub read buffer size for TextPassDumper
[lhc/web/wiklou.git] / includes / objectcache / APCBagOStuff.php
1 <?php
2 /**
3 * Object caching using PHP's APC accelerator.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Cache
22 */
23
24 /**
25 * This is a wrapper for APC's shared memory functions
26 *
27 * @ingroup Cache
28 */
29 class APCBagOStuff extends BagOStuff {
30 /**
31 * @param string $key
32 * @param int $casToken [optional]
33 * @return mixed
34 */
35 public function get( $key, &$casToken = null ) {
36 $val = apc_fetch( $key );
37
38 $casToken = $val;
39
40 if ( is_string( $val ) ) {
41 if ( $this->isInteger( $val ) ) {
42 $val = intval( $val );
43 } else {
44 $val = unserialize( $val );
45 }
46 }
47
48 return $val;
49 }
50
51 /**
52 * @param string $key
53 * @param mixed $value
54 * @param int $exptime
55 * @return bool
56 */
57 public function set( $key, $value, $exptime = 0 ) {
58 if ( !$this->isInteger( $value ) ) {
59 $value = serialize( $value );
60 }
61
62 apc_store( $key, $value, $exptime );
63
64 return true;
65 }
66
67 /**
68 * @param mixed $casToken
69 * @param string $key
70 * @param mixed $value
71 * @param int $exptime
72 * @return bool
73 * @throws MWException
74 */
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__ );
78 }
79
80 /**
81 * @param string $key
82 * @return bool
83 */
84 public function delete( $key ) {
85 apc_delete( $key );
86
87 return true;
88 }
89
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
96 */
97 public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
98 return $this->mergeViaLock( $key, $callback, $exptime, $attempts );
99 }
100
101 public function incr( $key, $value = 1 ) {
102 return apc_inc( $key, $value );
103 }
104
105 public function decr( $key, $value = 1 ) {
106 return apc_dec( $key, $value );
107 }
108 }