From 5e2376eb94f8d043283e8acc3c74ae93fba1da44 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Wed, 17 Aug 2016 23:25:37 -0700 Subject: [PATCH] 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 --- includes/PageProps.php | 12 +++++++++++- includes/libs/ProcessCacheLRU.php | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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; + } } -- 2.20.1