Allow requiring cache size for page props
authorStanislav Malyshev <smalyshev@gmail.com>
Thu, 18 Aug 2016 06:25:37 +0000 (23:25 -0700)
committerStanislav Malyshev <smalyshev@gmail.com>
Thu, 18 Aug 2016 19:57:34 +0000 (12:57 -0700)
Needed for batch processing where size of the batch is known
and the batch should fit in cache.

Change-Id: Ib6d6e6ab7e12788c934cd0e973bc35e133aeccbb

includes/PageProps.php
includes/libs/ProcessCacheLRU.php

index 3654384..5579ba5 100644 (file)
@@ -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
index 5a93391..03e23ed 100644 (file)
@@ -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;
+       }
 }