MediaWiki  REL1_19
MemcachedPhpBagOStuff.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class MemcachedPhpBagOStuff extends BagOStuff {
00007 
00011         protected $client;
00012 
00026         function __construct( $params ) {
00027                 if ( !isset( $params['servers'] ) ) {
00028                         $params['servers'] = $GLOBALS['wgMemCachedServers'];
00029                 }
00030                 if ( !isset( $params['debug'] ) ) {
00031                         $params['debug'] = $GLOBALS['wgMemCachedDebug'];
00032                 }
00033                 if ( !isset( $params['persistent'] ) ) {
00034                         $params['persistent'] = $GLOBALS['wgMemCachedPersistent'];
00035                 }
00036                 if  ( !isset( $params['compress_threshold'] ) ) {
00037                         $params['compress_threshold'] = 1500;
00038                 }
00039                 if ( !isset( $params['timeout'] ) ) {
00040                         $params['timeout'] = $GLOBALS['wgMemCachedTimeout'];
00041                 }
00042                 if ( !isset( $params['connect_timeout'] ) ) {
00043                         $params['connect_timeout'] = 0.1;
00044                 }
00045 
00046                 $this->client = new MemCachedClientforWiki( $params );
00047                 $this->client->set_servers( $params['servers'] );
00048                 $this->client->set_debug( $params['debug'] );
00049         }
00050 
00054         public function setDebug( $debug ) {
00055                 $this->client->set_debug( $debug );
00056         }
00057 
00062         public function get( $key ) {
00063                 return $this->client->get( $this->encodeKey( $key ) );
00064         }
00065 
00072         public function set( $key, $value, $exptime = 0 ) {
00073                 return $this->client->set( $this->encodeKey( $key ), $value, $exptime );
00074         }
00075 
00081         public function delete( $key, $time = 0 ) {
00082                 return $this->client->delete( $this->encodeKey( $key ), $time );
00083         }
00084 
00090         public function lock( $key, $timeout = 0 ) {
00091                 return $this->client->lock( $this->encodeKey( $key ), $timeout );
00092         }
00093 
00098         public function unlock( $key ) {
00099                 return $this->client->unlock( $this->encodeKey( $key ) );
00100         }
00101 
00107         public function add( $key, $value, $exptime = 0 ) {
00108                 return $this->client->add( $this->encodeKey( $key ), $value, $exptime );
00109         }
00110 
00117         public function replace( $key, $value, $exptime = 0 ) {
00118                 return $this->client->replace( $this->encodeKey( $key ), $value, $exptime );
00119         }
00120 
00126         public function incr( $key, $value = 1 ) {
00127                 return $this->client->incr( $this->encodeKey( $key ), $value );
00128         }
00129 
00135         public function decr( $key, $value = 1 ) {
00136                 return $this->client->decr( $this->encodeKey( $key ), $value );
00137         }
00138 
00145         public function getClient() {
00146                 return $this->client;
00147         }
00148 
00157         public function encodeKey( $key ) {
00158                 return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/', 
00159                         array( $this, 'encodeKeyCallback' ), $key );
00160         }
00161 
00162         protected function encodeKeyCallback( $m ) {
00163                 return rawurlencode( $m[0] );
00164         }
00165 
00174         public function decodeKey( $key ) {
00175                 return urldecode( $key );
00176         }
00177 }
00178