client->get( $this->encodeKey( $key ), $casToken ); } /** * @param string $key * @param mixed $value * @param int $exptime * @return bool */ public function set( $key, $value, $exptime = 0 ) { return $this->client->set( $this->encodeKey( $key ), $value, $this->fixExpiry( $exptime ) ); } /** * @param mixed $casToken * @param string $key * @param mixed $value * @param int $exptime * @return bool */ protected function cas( $casToken, $key, $value, $exptime = 0 ) { return $this->client->cas( $casToken, $this->encodeKey( $key ), $value, $this->fixExpiry( $exptime ) ); } /** * @param string $key * @return bool */ public function delete( $key ) { return $this->client->delete( $this->encodeKey( $key ) ); } /** * @param string $key * @param int $value * @param int $exptime (default 0) * @return mixed */ public function add( $key, $value, $exptime = 0 ) { return $this->client->add( $this->encodeKey( $key ), $value, $this->fixExpiry( $exptime ) ); } public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) { if ( !is_callable( $callback ) ) { throw new Exception( "Got invalid callback." ); } return $this->mergeViaCas( $key, $callback, $exptime, $attempts ); } /** * Get the underlying client object. This is provided for debugging * purposes. * @return BagOStuff */ public function getClient() { return $this->client; } /** * Encode a key for use on the wire inside the memcached protocol. * * We encode spaces and line breaks to avoid protocol errors. We encode * the other control characters for compatibility with libmemcached * verify_key. We leave other punctuation alone, to maximise backwards * compatibility. * @param string $key * @return string */ public function encodeKey( $key ) { return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/', array( $this, 'encodeKeyCallback' ), $key ); } /** * @param array $m * @return string */ protected function encodeKeyCallback( $m ) { return rawurlencode( $m[0] ); } /** * TTLs higher than 30 days will be detected as absolute TTLs * (UNIX timestamps), and will result in the cache entry being * discarded immediately because the expiry is in the past. * Clamp expires >30d at 30d, unless they're >=1e9 in which * case they are likely to really be absolute (1e9 = 2011-09-09) * @param int $expiry * @return int */ function fixExpiry( $expiry ) { if ( $expiry > 2592000 && $expiry < 1000000000 ) { $expiry = 2592000; } return (int)$expiry; } /** * Decode a key encoded with encodeKey(). This is provided as a convenience * function for debugging. * * @param string $key * * @return string */ public function decodeKey( $key ) { return urldecode( $key ); } /** * Send a debug message to the log * @param string $text */ protected function debugLog( $text ) { $this->logger->debug( $text ); } public function modifySimpleRelayEvent( array $event ) { if ( array_key_exists( 'val', $event ) ) { $event['flg'] = 0; // data is not serialized nor gzipped (for memcached driver) } return $event; } }