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
25 * This is a wrapper for APC's shared memory functions
29 class APCBagOStuff
extends BagOStuff
{
32 * @param int $casToken [optional]
35 public function get( $key, &$casToken = null ) {
36 $val = apc_fetch( $key );
40 if ( is_string( $val ) ) {
41 if ( $this->isInteger( $val ) ) {
42 $val = intval( $val );
44 $val = unserialize( $val );
57 public function set( $key, $value, $exptime = 0 ) {
58 if ( !$this->isInteger( $value ) ) {
59 $value = serialize( $value );
62 apc_store( $key, $value, $exptime );
68 * @param mixed $casToken
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__
);
84 public function delete( $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 );