*/
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 getMulti( array $keys ) {
- $res = array();
- foreach ( $keys as $key ) {
- $res[$key] = $this->get( $key );
- }
- return $res;
- }
-
/**
* Set an item.
* @param $key string
/* *** Emulated functions *** */
+ /**
+ * Get an associative array containing the item for each of the keys that have items.
+ * @param $keys Array List of strings
+ * @return Array
+ */
+ public function getMulti( array $keys ) {
+ $res = array();
+ foreach ( $keys as $key ) {
+ $val = $this->get( $key );
+ if ( $val !== false ) {
+ $res[$key] = $val;
+ }
+ }
+ return $res;
+ }
+
/**
* @param $key string
* @param $value mixed
* @return bool success
*/
public function add( $key, $value, $exptime = 0 ) {
- if ( !$this->get( $key ) ) {
+ if ( $this->get( $key ) === false ) {
return $this->set( $key, $value, $exptime );
}
- return true;
+ return false; // key already set
}
/**
if ( $this->get( $key ) !== false ) {
return $this->set( $key, $value, $exptime );
}
- return true;
+ return false; // key not already set
}
/**