diff --git a/classes/class_cache.php b/classes/class_cache.php index 3b4fdc8d..8521dd3c 100644 --- a/classes/class_cache.php +++ b/classes/class_cache.php @@ -34,6 +34,10 @@ class CACHE extends Memcache { public $MemcacheDBKey = ''; protected $InTransaction = false; public $Time = 0; + private $PersistentKeys = array( + 'stats_*', + 'percentiles_*', + ); public $CanClear = false; @@ -77,14 +81,16 @@ public function get_value($Key, $NoCache=false) { trigger_error("Cache retrieval failed for empty key"); } - if (isset($_GET['clearcache']) && $this->CanClear) { + if (isset($_GET['clearcache']) && $this->CanClear && !in_array_partial($Key, $this->PersistentKeys)) { if ($_GET['clearcache'] == 1) { //Because check_perms isn't true until loggeduser is pulled from the cache, we have to remove the entries loaded before the loggeduser data //Because of this, not user cache data will require a secondary pageload following the clearcache to update if (count($this->CacheHits) > 0) { - foreach ($this->CacheHits as $Key => $Entry) { - $this->delete($Key); - unset($this->CacheHits[$Key]); + foreach (array_keys($this->CacheHits) as $HitKey) { + if (!in_array_partial($HitKey, $this->PersistentKeys)) { + $this->delete($HitKey); + unset($this->CacheHits[$HitKey]); + } } } $this->delete($Key); diff --git a/classes/script_start.php b/classes/script_start.php index 656a1b31..da6051d3 100644 --- a/classes/script_start.php +++ b/classes/script_start.php @@ -1901,6 +1901,31 @@ function starts_with($Haystack, $Needle) { return strpos($Haystack, $Needle) === 0; } +/** + * Variant of in_array() with trailing wildcard support + * @param string $Needle, array $Haystack + * @return true if (substring of) $Needle exists in $Haystack + */ +function in_array_partial($Needle, $Haystack) { + static $Searches = array(); + if(array_key_exists($Needle, $Searches)) { + return $Searches[$Needle]; + } + foreach($Haystack as $String) { + if(substr($String, -1) == '*') { + if(!strncmp($Needle, $String, strlen($String)-1)) { + $Searches[$Needle] = true; + return true; + } + } elseif(!strcmp($Needle, $String)) { + $Searches[$Needle] = true; + return true; + } + } + $Searches[$Needle] = false; + return false; +} + $Debug->set_flag('ending function definitions');