From 7572c9097aea029d8e663cf782a89be95e268e92 Mon Sep 17 00:00:00 2001 From: Juan Osorio Date: Thu, 13 Dec 2018 11:31:17 -0800 Subject: [PATCH] objectcache: Fixes WinCache increment losing TTL. WinCache incr function adds a number to the value of a key, but in the process loses the Time To Live of the cache entry. This fixes such bug. Bug: T211914 Change-Id: I02889e63b95188b8d5123a9788a020ca3aa7d1b1 --- .../libs/objectcache/WinCacheBagOStuff.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/includes/libs/objectcache/WinCacheBagOStuff.php b/includes/libs/objectcache/WinCacheBagOStuff.php index 9c6c907c02..764230bf8f 100644 --- a/includes/libs/objectcache/WinCacheBagOStuff.php +++ b/includes/libs/objectcache/WinCacheBagOStuff.php @@ -97,4 +97,27 @@ class WinCacheBagOStuff extends BagOStuff { return $keyspace . ':' . implode( ':', $args ); } + + /** + * Increase stored value of $key by $value while preserving its original TTL + * @param string $key Key to increase + * @param int $value Value to add to $key (Default 1) + * @return int|bool New value or false on failure + */ + public function incr( $key, $value = 1 ) { + if ( !$this->lock( $key ) ) { + return false; + } + $n = $this->get( $key ); + if ( $this->isInteger( $n ) ) { // key exists? + $n += intval( $value ); + $oldTTL = wincache_ucache_info( false, $key )["ucache_entries"][1]["ttl_seconds"]; + $this->set( $key, max( 0, $n ), $oldTTL ); + } else { + $n = false; + } + $this->unlock( $key ); + + return $n; + } } -- 2.20.1