MediaWiki  REL1_22
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 
00116     public function replace( $key, $value, $exptime = 0 ) {
00117         return $this->client->replace( $this->encodeKey( $key ), $value,
00118             $this->fixExpiry( $exptime ) );
00119     }
00120 
00125     public function getClient() {
00126         return $this->client;
00127     }
00128 
00139     public function encodeKey( $key ) {
00140         return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/',
00141             array( $this, 'encodeKeyCallback' ), $key );
00142     }
00143 
00148     protected function encodeKeyCallback( $m ) {
00149         return rawurlencode( $m[0] );
00150     }
00151 
00159     function fixExpiry( $expiry ) {
00160         if ( $expiry > 2592000 && $expiry < 1000000000 ) {
00161             $expiry = 2592000;
00162         }
00163         return $expiry;
00164     }
00165 
00174     public function decodeKey( $key ) {
00175         return urldecode( $key );
00176     }
00177 
00181     protected function debugLog( $text ) {
00182         if ( substr( $text, -1 ) !== "\n" ) {
00183             $text .= "\n";
00184         }
00185         wfDebugLog( 'memcached', $text );
00186     }
00187 }