MediaWiki  REL1_23
MemcachedBagOStuff.php
Go to the documentation of this file.
00001 <?php
00029 class MemcachedBagOStuff extends BagOStuff {
00030     protected $client;
00031 
00036     protected function applyDefaultParams( $params ) {
00037         if ( !isset( $params['servers'] ) ) {
00038             $params['servers'] = $GLOBALS['wgMemCachedServers'];
00039         }
00040         if ( !isset( $params['debug'] ) ) {
00041             $params['debug'] = $GLOBALS['wgMemCachedDebug'];
00042         }
00043         if ( !isset( $params['persistent'] ) ) {
00044             $params['persistent'] = $GLOBALS['wgMemCachedPersistent'];
00045         }
00046         if ( !isset( $params['compress_threshold'] ) ) {
00047             $params['compress_threshold'] = 1500;
00048         }
00049         if ( !isset( $params['timeout'] ) ) {
00050             $params['timeout'] = $GLOBALS['wgMemCachedTimeout'];
00051         }
00052         if ( !isset( $params['connect_timeout'] ) ) {
00053             $params['connect_timeout'] = 0.5;
00054         }
00055         return $params;
00056     }
00057 
00063     public function get( $key, &$casToken = null ) {
00064         return $this->client->get( $this->encodeKey( $key ), $casToken );
00065     }
00066 
00073     public function set( $key, $value, $exptime = 0 ) {
00074         return $this->client->set( $this->encodeKey( $key ), $value,
00075             $this->fixExpiry( $exptime ) );
00076     }
00077 
00085     public function cas( $casToken, $key, $value, $exptime = 0 ) {
00086         return $this->client->cas( $casToken, $this->encodeKey( $key ),
00087             $value, $this->fixExpiry( $exptime ) );
00088     }
00089 
00095     public function delete( $key, $time = 0 ) {
00096         return $this->client->delete( $this->encodeKey( $key ), $time );
00097     }
00098 
00105     public function add( $key, $value, $exptime = 0 ) {
00106         return $this->client->add( $this->encodeKey( $key ), $value,
00107             $this->fixExpiry( $exptime ) );
00108     }
00109 
00114     public function getClient() {
00115         return $this->client;
00116     }
00117 
00128     public function encodeKey( $key ) {
00129         return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/',
00130             array( $this, 'encodeKeyCallback' ), $key );
00131     }
00132 
00137     protected function encodeKeyCallback( $m ) {
00138         return rawurlencode( $m[0] );
00139     }
00140 
00148     function fixExpiry( $expiry ) {
00149         if ( $expiry > 2592000 && $expiry < 1000000000 ) {
00150             $expiry = 2592000;
00151         }
00152         return $expiry;
00153     }
00154 
00163     public function decodeKey( $key ) {
00164         return urldecode( $key );
00165     }
00166 
00170     protected function debugLog( $text ) {
00171         wfDebugLog( 'memcached', $text );
00172     }
00173 }