Prepare 1.31.5
[lhc/web/wiklou.git] / includes / libs / ProcessCacheLRU.php
index eec31ce..b374259 100644 (file)
 use Wikimedia\Assert\Assert;
 
 /**
- * Handles per process caching of items
+ * Class for process caching individual properties of expiring items
+ *
+ * When the key for an entire item is deleted, all properties for it are deleted
+ *
  * @ingroup Cache
  */
 class ProcessCacheLRU {
-       /** @var Array */
-       protected $cache = array(); // (key => prop => value)
+       /** @var array */
+       protected $cache = []; // (key => prop => value)
 
-       /** @var Array */
-       protected $cacheTimes = array(); // (key => prop => UNIX timestamp)
+       /** @var array */
+       protected $cacheTimes = []; // (key => prop => UNIX timestamp)
 
        protected $maxCacheKeys; // integer; max entries
 
@@ -109,8 +112,8 @@ class ProcessCacheLRU {
         */
        public function clear( $keys = null ) {
                if ( $keys === null ) {
-                       $this->cache = array();
-                       $this->cacheTimes = array();
+                       $this->cache = [];
+                       $this->cacheTimes = [];
                } else {
                        foreach ( (array)$keys as $key ) {
                                unset( $this->cache[$key] );
@@ -149,4 +152,12 @@ class ProcessCacheLRU {
                unset( $this->cache[$key] );
                $this->cache[$key] = $item;
        }
+
+       /**
+        * Get cache size
+        * @return int
+        */
+       public function getSize() {
+               return $this->maxCacheKeys;
+       }
 }