MediaWiki
REL1_20
|
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 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, 00074 $this->fixExpiry( $exptime ) ); 00075 } 00076 00082 public function delete( $key, $time = 0 ) { 00083 return $this->client->delete( $this->encodeKey( $key ), $time ); 00084 } 00085 00092 public function add( $key, $value, $exptime = 0 ) { 00093 return $this->client->add( $this->encodeKey( $key ), $value, 00094 $this->fixExpiry( $exptime ) ); 00095 } 00096 00103 public function replace( $key, $value, $exptime = 0 ) { 00104 return $this->client->replace( $this->encodeKey( $key ), $value, 00105 $this->fixExpiry( $exptime ) ); 00106 } 00107 00112 public function getClient() { 00113 return $this->client; 00114 } 00115 00126 public function encodeKey( $key ) { 00127 return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/', 00128 array( $this, 'encodeKeyCallback' ), $key ); 00129 } 00130 00135 protected function encodeKeyCallback( $m ) { 00136 return rawurlencode( $m[0] ); 00137 } 00138 00146 function fixExpiry( $expiry ) { 00147 if ( $expiry > 2592000 && $expiry < 1000000000 ) { 00148 $expiry = 2592000; 00149 } 00150 return $expiry; 00151 } 00152 00161 public function decodeKey( $key ) { 00162 return urldecode( $key ); 00163 } 00164 00168 protected function debugLog( $text ) { 00169 global $wgDebugLogGroups; 00170 if( !isset( $wgDebugLogGroups['memcached'] ) ) { 00171 # Prefix message since it will end up in main debug log file 00172 $text = "memcached: $text"; 00173 } 00174 if ( substr( $text, -1 ) !== "\n" ) { 00175 $text .= "\n"; 00176 } 00177 wfDebugLog( 'memcached', $text ); 00178 } 00179 } 00180