Page MenuHomePhabricator
Paste P3530

APCuBagOStuff WIP for T140961
ActivePublic

Authored by Reedy on Jul 20 2016, 11:18 PM.
Tags
None
Referenced Files
F4292941: APCuBagOStuff WIP for T140961
Jul 20 2016, 11:18 PM
Subscribers
None
commit 9f6228794ad6faedc3550ffa69950660576013aa
Author: Reedy <reedy@wikimedia.org>
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 @@
+<?php
+/**
+ * Object caching using PHP's APC accelerator.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Cache
+ */
+
+/**
+ * This is a wrapper for APCu's shared memory functions
+ *
+ * @ingroup Cache
+ */
+class APCuBagOStuff extends APCBagOStuff {
+ /**
+ * Constructor
+ *
+ * Available parameters are:
+ * - nativeSerialize: If true, pass objects to apcu_store(), and trust it
+ * to serialize them correctly. If false, serialize
+ * all values in PHP.
+ *
+ * @param array $params
+ */
+ public function __construct( array $params = [] ) {
+ parent::__construct( $params );
+ }
+
+ public function set( $key, $value, $exptime = 0, $flags = 0 ) {
+ if ( !$this->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' ] );

Event Timeline