commit 9f6228794ad6faedc3550ffa69950660576013aa Author: Reedy Date: Mon Jul 18 00:44:11 2016 +0100 Detect/use APCu properly In PHP 5.5 and above, userland APC caching moved to an extension Bug: T140587 Change-Id: Ie0871776cd7e67838471a4fe95451cf4164079b7 diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 4d5aa7a..9384ca1 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -242,7 +242,8 @@ abstract class Installer { */ protected $objectCaches = [ 'xcache' => 'xcache_get', - 'apc' => 'apc_fetch', + 'apc' => 'apcu_fetch', + 'apcu' => 'apcu_fetch', 'wincache' => 'wincache_ucache_get' ]; diff --git a/includes/libs/MemoizedCallable.php b/includes/libs/MemoizedCallable.php index 50e9732..c20c4ac 100644 --- a/includes/libs/MemoizedCallable.php +++ b/includes/libs/MemoizedCallable.php @@ -77,7 +77,9 @@ class MemoizedCallable { */ protected function fetchResult( $key, &$success ) { $success = false; - if ( function_exists( 'apc_fetch' ) ) { + if ( function_exists( 'apcu_fetch' ) ) { + return apcu_fetch( $key, success ); + } elseif ( function_exists( 'apc_fetch' ) ) { return apc_fetch( $key, $success ); } return false; @@ -90,7 +92,9 @@ class MemoizedCallable { * @param mixed $result */ protected function storeResult( $key, $result ) { - if ( function_exists( 'apc_store' ) ) { + if ( function_exists( 'apcu_store' ) ) { + apcu_store( $key, $result, $this->ttl ); + } elseif ( function_exists( 'apc_store' ) ) { apc_store( $key, $result, $this->ttl ); } } diff --git a/includes/libs/objectcache/APCuBagOStuff.php b/includes/libs/objectcache/APCuBagOStuff.php new file mode 100644 index 0000000..693e558 --- /dev/null +++ b/includes/libs/objectcache/APCuBagOStuff.php @@ -0,0 +1,67 @@ +nativeSerialize && !$this->isInteger( $value ) ) { + $value = serialize( $value ); + } + + apcu_store( $key . self::KEY_SUFFIX, $value, $exptime ); + + return true; + } + + public function delete( $key ) { + apcu_delete( $key . self::KEY_SUFFIX ); + + return true; + } + + public function incr( $key, $value = 1 ) { + return apc_inc( $key . self::KEY_SUFFIX, $value ); + } + + public function decr( $key, $value = 1 ) { + return apc_dec( $key . self::KEY_SUFFIX, $value ); + } +} diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index e1bb2db..0891450 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -259,7 +259,9 @@ class ObjectCache { * @since 1.27 */ public static function getLocalServerInstance( $fallback = CACHE_NONE ) { - if ( function_exists( 'apc_fetch' ) ) { + if ( function_exists( 'apcu_fetch' ) ) { + $id = 'apcu'; + } elseif ( function_exists( 'apc_fetch' ) { $id = 'apc'; } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { $id = 'xcache'; diff --git a/tests/phpunit/includes/libs/MemoizedCallableTest.php b/tests/phpunit/includes/libs/MemoizedCallableTest.php index 6eb96b1..4d3a629 100644 --- a/tests/phpunit/includes/libs/MemoizedCallableTest.php +++ b/tests/phpunit/includes/libs/MemoizedCallableTest.php @@ -44,7 +44,7 @@ class MemoizedCallableTest extends PHPUnit_Framework_TestCase { * Consecutive calls to the memoized callable with the same arguments * should result in just one invocation of the underlying callable. * - * @requires function apc_store + * @requires function apcu_store/apc_store */ public function testCallableMemoized() { $observer = $this->getMock( 'stdClass', [ 'computeSomething' ] );