MediaWiki  REL1_24
MemcachedBagOStuff.php
Go to the documentation of this file.
00001 <?php
00029 class MemcachedBagOStuff extends BagOStuff {
00030     protected $client;
00031 
00038     protected function applyDefaultParams( $params ) {
00039         if ( !isset( $params['servers'] ) ) {
00040             $params['servers'] = $GLOBALS['wgMemCachedServers'];
00041         }
00042         if ( !isset( $params['debug'] ) ) {
00043             $params['debug'] = $GLOBALS['wgMemCachedDebug'];
00044         }
00045         if ( !isset( $params['persistent'] ) ) {
00046             $params['persistent'] = $GLOBALS['wgMemCachedPersistent'];
00047         }
00048         if ( !isset( $params['compress_threshold'] ) ) {
00049             $params['compress_threshold'] = 1500;
00050         }
00051         if ( !isset( $params['timeout'] ) ) {
00052             $params['timeout'] = $GLOBALS['wgMemCachedTimeout'];
00053         }
00054         if ( !isset( $params['connect_timeout'] ) ) {
00055             $params['connect_timeout'] = 0.5;
00056         }
00057         return $params;
00058     }
00059 
00065     public function get( $key, &$casToken = null ) {
00066         return $this->client->get( $this->encodeKey( $key ), $casToken );
00067     }
00068 
00075     public function set( $key, $value, $exptime = 0 ) {
00076         return $this->client->set( $this->encodeKey( $key ), $value,
00077             $this->fixExpiry( $exptime ) );
00078     }
00079 
00087     public function cas( $casToken, $key, $value, $exptime = 0 ) {
00088         return $this->client->cas( $casToken, $this->encodeKey( $key ),
00089             $value, $this->fixExpiry( $exptime ) );
00090     }
00091 
00097     public function delete( $key, $time = 0 ) {
00098         return $this->client->delete( $this->encodeKey( $key ), $time );
00099     }
00100 
00107     public function add( $key, $value, $exptime = 0 ) {
00108         return $this->client->add( $this->encodeKey( $key ), $value,
00109             $this->fixExpiry( $exptime ) );
00110     }
00111 
00117     public function getClient() {
00118         return $this->client;
00119     }
00120 
00131     public function encodeKey( $key ) {
00132         return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/',
00133             array( $this, 'encodeKeyCallback' ), $key );
00134     }
00135 
00140     protected function encodeKeyCallback( $m ) {
00141         return rawurlencode( $m[0] );
00142     }
00143 
00153     function fixExpiry( $expiry ) {
00154         if ( $expiry > 2592000 && $expiry < 1000000000 ) {
00155             $expiry = 2592000;
00156         }
00157         return (int)$expiry;
00158     }
00159 
00168     public function decodeKey( $key ) {
00169         return urldecode( $key );
00170     }
00171 
00176     protected function debugLog( $text ) {
00177         wfDebugLog( 'memcached', $text );
00178     }
00179 }