*/
abstract public function get( $key );
+ /**
+ * Get an associative array containing the item for each of the given keys.
+ * Each item will be false if it does not exist.
+ * @param $keys Array List of strings
+ *
+ * @return Array
+ */
+ public function getBatch( array $keys ) {
+ $res = array();
+ foreach ( $keys as $key ) {
+ $res[$key] = $this->get( $key );
+ }
+ return $res;
+ }
+
/**
* Set an item.
* @param $key string
return $this->client->get( $this->encodeKey( $key ) );
}
+ /**
+ * @param $keys Array
+ * @return Array
+ */
+ public function getBatch( array $keys ) {
+ $callback = array( $this, 'encodeKey' );
+ return $this->client->get_multi( array_map( $callback, $keys ) );
+ }
+
/**
* @param $key string
* @param $value
}
/**
- * Get the underlying client object. This is provided for debugging
+ * Get the underlying client object. This is provided for debugging
* purposes.
*
* @return MemCachedClientforWiki
/**
* 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
+ * 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.
* @return string
*/
public function encodeKey( $key ) {
- return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/',
+ return preg_replace_callback( '/[\x00-\x20\x25\x7f]+/',
array( $this, 'encodeKeyCallback' ), $key );
}
}
/**
- * Decode a key encoded with encodeKey(). This is provided as a convenience
+ * Decode a key encoded with encodeKey(). This is provided as a convenience
* function for debugging.
*
* @param $key string