/** * Tries to load a cached entry. * If existing, a valid object is returned. * Otherwise, e.g. if not found or invalid, * null is returned instead. * * @param string $strSourceName * @param string $strHash1 * @param string $strHash2 * @param string $strLanguage * @param bool $bitCreateInstanceOnNotFound if no entry was found, a new instance is created and returned. Set the content afterwards! * @return class_cache or null */ public static function getCachedEntry($strSourceName, $strHash1, $strHash2 = null, $strLanguage = null, $bitCreateInstanceOnNotFound = false) { self::$intRequests++; //first run - search the internal cache foreach (self::$arrInternalCache as $arrSingleCacheEntry) { if ($arrSingleCacheEntry["cache_source"] == $strSourceName && $arrSingleCacheEntry["cache_hash1"] == $strHash1 && ($strHash2 == null || $arrSingleCacheEntry["cache_hash2"] == $strHash2) && ($strLanguage == null || $arrSingleCacheEntry["cache_language"] == $strLanguage)) { $objCacheEntry = new class_cache($arrSingleCacheEntry["cache_source"], $arrSingleCacheEntry["cache_hash1"], $arrSingleCacheEntry["cache_hash2"], $arrSingleCacheEntry["cache_language"], $arrSingleCacheEntry["cache_content"], $arrSingleCacheEntry["cache_leasetime"], $arrSingleCacheEntry["cache_id"]); self::$intHits++; if (_cache_ === true) { $objCacheEntry->increaseCacheEntryHits(); } return $objCacheEntry; } } //search in the database to find a matching entry $strQuery = "SELECT *\n FROM " . _dbprefix_ . "cache\n WHERE cache_source = ?\n AND cache_hash1 = ?\n " . ($strHash2 != null ? " AND cache_hash2 = ? " : "") . "\n " . ($strLanguage != null ? " AND cache_language = ? " : "") . "\n AND cache_leasetime > ? "; $arrParams = array($strSourceName, $strHash1); if ($strHash2 != null) { $arrParams[] = $strHash2; } if ($strLanguage != null) { $arrParams[] = $strLanguage; } $arrParams[] = time(); $arrRow = class_carrier::getInstance()->getObjDB()->getPRow($strQuery, $arrParams); if (isset($arrRow["cache_id"])) { $objCacheEntry = new class_cache($arrRow["cache_source"], $arrRow["cache_hash1"], $arrRow["cache_hash2"], $arrRow["cache_language"], $arrRow["cache_content"], $arrRow["cache_leasetime"], $arrRow["cache_id"]); self::$intHits++; if (_cache_ === true) { $objCacheEntry->increaseCacheEntryHits(); } return $objCacheEntry; } else { //entry not existing, return null or create a new one? if ($bitCreateInstanceOnNotFound) { $objCache = class_cache::createNewInstance($strSourceName); $objCache->setStrHash1($strHash1); $objCache->setStrHash2($strHash2); $objCache->setStrLanguage($strLanguage); return $objCache; } return null; } }