From c5e336c9adfae898c7224e3180e4e3c59108f14d Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 20 Sep 2012 12:24:14 -0700 Subject: [PATCH] [FileBackend] Fallback to $wgMemc for swift auth caching in cli mode. Change-Id: I4338c68a18f1424b0d0ec4fe3fcf77c79ba774c8 --- includes/filebackend/SwiftFileBackend.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index abe834ac76..185a557ff7 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -81,7 +81,8 @@ class SwiftFileBackend extends FileBackendStore { * - levels : the number of hash levels (and digits) * - repeat : hash subdirectories are prefixed with all the * parent hash directory names (e.g. "a/ab/abc") - * - cacheAuthInfo : Whether to cache authentication tokens in APC/XCache. + * - cacheAuthInfo : Whether to cache authentication tokens in APC, XCache, ect. + * If those are not available, then the main cache will be used. * This is probably insecure in shared hosting environments. */ public function __construct( array $config ) { @@ -121,9 +122,13 @@ class SwiftFileBackend extends FileBackendStore { $this->connContainerCache = new ProcessCacheLRU( 300 ); // Cache auth token information to avoid RTTs if ( !empty( $config['cacheAuthInfo'] ) ) { - try { // look for APC, XCache, WinCache, ect... - $this->srvCache = ObjectCache::newAccelerator( array() ); - } catch ( Exception $e ) {} + if ( php_sapi_name() === 'cli' ) { + $this->srvCache = wfGetMainCache(); // preferrably memcached + } else { + try { // look for APC, XCache, WinCache, ect... + $this->srvCache = ObjectCache::newAccelerator( array() ); + } catch ( Exception $e ) {} + } } $this->srvCache = $this->srvCache ? $this->srvCache : new EmptyBagOStuff(); } -- 2.20.1