X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fobjectcache%2FBagOStuff.php;h=56f1be23b5252792cbd636a9f82defb45db06287;hb=13e33c28983461d5b8bdc1dece0cd0a35347a261;hp=99f73aabe2cfeeac3286e3066edefceb6756a566;hpb=27ca77bdd2512a27c58547d810a5206cc4c12b22;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/objectcache/BagOStuff.php b/includes/objectcache/BagOStuff.php index 99f73aabe2..56f1be23b5 100644 --- a/includes/objectcache/BagOStuff.php +++ b/includes/objectcache/BagOStuff.php @@ -247,6 +247,23 @@ abstract class BagOStuff { return $res; } + /** + * Batch insertion + * @param array $data $key => $value assoc array + * @param int $exptime Either an interval in seconds or a unix timestamp for expiry + * @return bool success + * @since 1.24 + */ + public function setMulti( array $data, $exptime = 0 ) { + $res = true; + foreach ( $data as $key => $value ) { + if ( !$this->set( $key, $value, $exptime ) ) { + $res = false; + } + } + return $res; + } + /** * @param string $key * @param mixed $value @@ -307,6 +324,23 @@ abstract class BagOStuff { return $this->incr( $key, - $value ); } + /** + * Increase stored value of $key by $value while preserving its TTL + * + * This will create the key with value $init and TTL $ttl if not present + * + * @param string $key + * @param integer $ttl + * @param integer $value + * @param integer $init + * @return bool + * @since 1.24 + */ + public function incrWithInit( $key, $ttl, $value = 1, $init = 1 ) { + return $this->incr( $key, $value ) || + $this->add( $key, $init, $ttl ) || $this->incr( $key, $value ); + } + /** * Get the "last error" registered; clearLastError() should be called manually * @return int ERR_* constant for the "last error" registry