From 3817818aca9733684a9dd0e75d7c3168ddf3f033 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 4 Feb 2015 18:22:08 -0800 Subject: [PATCH] Add a ReplicatedBagOStuff class Bug: T88634 Change-Id: I1f7cccd6ac376055ff2b84641ff38a85571c65b0 --- autoload.php | 1 + includes/objectcache/ReplicatedBagOStuff.php | 126 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 includes/objectcache/ReplicatedBagOStuff.php diff --git a/autoload.php b/autoload.php index a5560f23a0..705f5bda4e 100644 --- a/autoload.php +++ b/autoload.php @@ -964,6 +964,7 @@ $wgAutoloadLocalClasses = array( 'RenderAction' => __DIR__ . '/includes/actions/RenderAction.php', 'ReplacementArray' => __DIR__ . '/includes/libs/ReplacementArray.php', 'Replacer' => __DIR__ . '/includes/libs/replacers/Replacer.php', + 'ReplicatedBagOStuff' => __DIR__ . '/includes/objectcache/ReplicatedBagOStuff.php', 'RepoGroup' => __DIR__ . '/includes/filerepo/RepoGroup.php', 'RequestContext' => __DIR__ . '/includes/context/RequestContext.php', 'ResetUserTokens' => __DIR__ . '/maintenance/resetUserTokens.php', diff --git a/includes/objectcache/ReplicatedBagOStuff.php b/includes/objectcache/ReplicatedBagOStuff.php new file mode 100644 index 0000000000..8097308f69 --- /dev/null +++ b/includes/objectcache/ReplicatedBagOStuff.php @@ -0,0 +1,126 @@ +mCache = ( $params['masterCache'] instanceof BagOStuff ) + ? $params['masterCache'] + : ObjectCache::newFromParams( $params['masterCache'] ); + $this->sCache = ( $params['slaveCache'] instanceof BagOStuff ) + ? $params['slaveCache'] + : ObjectCache::newFromParams( $params['slaveCache'] ); + } + + public function setDebug( $debug ) { + $this->mCache->setDebug( $debug ); + $this->sCache->setDebug( $debug ); + } + + public function get( $key, &$casToken = null ) { + return $this->sCache->get( $key, $casToken ); + } + + public function getMulti( $keys ) { + return $this->sCache->getMulti( $keys ); + } + + public function set( $key, $value, $exptime = 0 ) { + return $this->mCache->set( $key, $value, $exptime ); + } + + public function delete( $key ) { + return $this->mCache->delete( $key ); + } + + public function add( $key, $value, $exptime = 0 ) { + return $this->mCache->add( $key, $value, $exptime ); + } + + public function incr( $key, $value = 1 ) { + return $this->mCache->incr( $key, $value ); + } + + public function decr( $key ) { + return $this->mCache->decr( $key ); + } + + public function lock( $key, $timeout = 6, $expiry = 6 ) { + return $this->mCache->lock( $key, $timeout, $expiry ); + } + + public function unlock( $key ) { + return $this->mCache->unlock( $key ); + } + + public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) { + return $this->mCache->merge( $key, $callback, $exptime, $attempts ); + } + + public function getLastError() { + return ( $this->mCache->getLastError() != self::ERR_NONE ) + ? $this->mCache->getLastError() + : $this->sCache->getLastError(); + } + + public function clearLastError() { + $this->mCache->clearLastError(); + $this->sCache->clearLastError(); + } + + protected function cas( $casToken, $key, $value, $exptime = 0 ) { + $this->mCache->cas( $casToken, $key, $value, $exptime ); + } +} -- 2.20.1