*/
private $listIndex = [];
+ /**
+ * Cached values from "expensive" method calls
+ */
+ private $cache = [
+ // Cached isValidHash() calls
+ 'is_valid' => [],
+ ];
+
/**
* Protected constructor
*
if (empty($hash)) {
// Throw IAE
throw new InvalidArgumentException('Parameter "hash" is empty');
+ } elseif (!isset($this->cache['is_valid'][$hash])) {
+ // Check it
+ $this->cache['is_valid'][$hash] = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash])));
}
- // Check it
- $isValid = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash])));
-
// Return the result
- return $isValid;
+ return $this->cache['is_valid'][$hash];
}
/**