X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fobjectcache%2FBagOStuff.php;h=e6ba04211cb66fc3c72d994c2288d75016c4420c;hb=bae670cf03d81b8128ba7aadcfaa61d3b381cf2c;hp=adb6abcd7b019152465a471fe9b450fa8bc6775d;hpb=be76d86932bea59ea18d729b28d05fbc4775cf25;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/objectcache/BagOStuff.php b/includes/objectcache/BagOStuff.php index adb6abcd7b..e6ba04211c 100644 --- a/includes/objectcache/BagOStuff.php +++ b/includes/objectcache/BagOStuff.php @@ -41,8 +41,11 @@ * @ingroup Cache */ abstract class BagOStuff { - var $debugMode = false; + private $debugMode = false; + /** + * @param $bool bool + */ public function setDebug( $bool ) { $this->debugMode = $bool; } @@ -53,6 +56,7 @@ abstract class BagOStuff { /** * Get an item with the given key. Returns false if it does not exist. * @param $key string + * @return mixed Returns false on failure */ abstract public function get( $key ); @@ -61,51 +65,108 @@ abstract class BagOStuff { * @param $key string * @param $value mixed * @param $exptime int Either an interval in seconds or a unix timestamp for expiry + * @return bool success */ abstract public function set( $key, $value, $exptime = 0 ); - /* + /** * Delete an item. * @param $key string * @param $time int Amount of time to delay the operation (mostly memcached-specific) + * @return bool True if the item was deleted or not found, false on failure */ abstract public function delete( $key, $time = 0 ); + /** + * @param $key string + * @param $timeout integer + * @return bool success + */ public function lock( $key, $timeout = 0 ) { /* stub */ return true; } + /** + * @param $key string + * @return bool success + */ public function unlock( $key ) { /* stub */ return true; } + /** + * @todo: what is this? + * @return Array + */ public function keys() { /* stub */ return array(); } + /** + * Delete all objects expiring before a certain date. + * @param $date string The reference date in MW format + * @param $progressCallback callback|bool Optional, a function which will be called + * regularly during long-running operations with the percentage progress + * as the first parameter. + * + * @return bool on success, false if unimplemented + */ + public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) { + // stub + return false; + } + /* *** Emulated functions *** */ - public function add( $key, $value, $exptime = 0 ) { - if ( !$this->get( $key ) ) { - $this->set( $key, $value, $exptime ); + /** + * 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; + } - return true; + /** + * @param $key string + * @param $value mixed + * @param $exptime integer + * @return bool success + */ + public function add( $key, $value, $exptime = 0 ) { + if ( $this->get( $key ) === false ) { + return $this->set( $key, $value, $exptime ); } + return false; // key already set } + /** + * @param $key string + * @param $value mixed + * @return bool success + */ public function replace( $key, $value, $exptime = 0 ) { if ( $this->get( $key ) !== false ) { - $this->set( $key, $value, $exptime ); + return $this->set( $key, $value, $exptime ); } + return false; // key not already set } /** * @param $key String: Key to increase * @param $value Integer: Value to add to $key (Default 1) * @return null if lock is not possible else $key value increased by $value + * @return success */ public function incr( $key, $value = 1 ) { if ( !$this->lock( $key ) ) { @@ -123,18 +184,29 @@ abstract class BagOStuff { return $n; } + /** + * @param $key String + * @param $value Integer + * @return bool success + */ public function decr( $key, $value = 1 ) { return $this->incr( $key, - $value ); } + /** + * @param $text string + */ public function debug( $text ) { if ( $this->debugMode ) { - wfDebug( "BagOStuff debug: $text\n" ); + $class = get_class( $this ); + wfDebug( "$class debug: $text\n" ); } } /** * Convert an optionally relative time to an absolute time + * @param $exptime integer + * @return int */ protected function convertExpiry( $exptime ) { if ( ( $exptime != 0 ) && ( $exptime < 86400 * 3650 /* 10 years */ ) ) { @@ -144,5 +216,3 @@ abstract class BagOStuff { } } } - -