From: Stanislav Malyshev Date: Thu, 18 Aug 2016 06:25:37 +0000 (-0700) Subject: Allow requiring cache size for page props X-Git-Tag: 1.31.0-rc.0~5988^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=5e2376eb94f8d043283e8acc3c74ae93fba1da44;p=lhc%2Fweb%2Fwiklou.git Allow requiring cache size for page props Needed for batch processing where size of the batch is known and the batch should fit in cache. Change-Id: Ib6d6e6ab7e12788c934cd0e973bc35e133aeccbb --- diff --git a/includes/PageProps.php b/includes/PageProps.php index 3654384722..5579ba5271 100644 --- a/includes/PageProps.php +++ b/includes/PageProps.php @@ -84,6 +84,16 @@ class PageProps { $this->cache = new ProcessCacheLRU( self::CACHE_SIZE ); } + /** + * Ensure that cache has at least this size + * @param int $size + */ + public function ensureCacheSize( $size ) { + if ( $this->cache->getSize() < $size ) { + $this->cache->resize( $size ); + } + } + /** * Given one or more Titles and one or more names of properties, * returns an associative array mapping page ID to property value. @@ -92,7 +102,7 @@ class PageProps { * single Title is provided, it does not need to be passed in an array, * but an array will always be returned. If a single property name is * provided, it does not need to be passed in an array. In that case, - * an associtive array mapping page ID to property value will be + * an associative array mapping page ID to property value will be * returned; otherwise, an associative array mapping page ID to * an associative array mapping property name to property value will be * returned. An empty array will be returned if no matching properties diff --git a/includes/libs/ProcessCacheLRU.php b/includes/libs/ProcessCacheLRU.php index 5a933914c6..03e23edbb7 100644 --- a/includes/libs/ProcessCacheLRU.php +++ b/includes/libs/ProcessCacheLRU.php @@ -149,4 +149,12 @@ class ProcessCacheLRU { unset( $this->cache[$key] ); $this->cache[$key] = $item; } + + /** + * Get cache size + * @return int + */ + public function getSize() { + return $this->maxCacheKeys; + } }