/** * Refreshes a single part of the cache provided there is a compatible rebuild* * method to do so. A part of the cache can be modules, sections or languages * since these all have their own caches that need to be dealt with. * * @param string $part which part of the cache to build * @param array $items List of items to be passed to the rebuild method * @param array $platforms List of platforms to carry out the refresh for * @param array $params Additional metadata parameters * @return null */ protected static function refreshCachePart($part, $items = array(), $platforms = array(), $params = array()) { // No args, no worries if (empty($items)) { return; } // If we are in the middle of a refresh do nothing if (self::$inProcess) { return; } // If we are in queue state (like in RepairAndRebuild), hold on to this // request until we are told to run it if (self::$isQueued) { self::buildCacheRefreshQueueSection($part, $items, array_merge($params, array('platforms' => $platforms))); return; } if (empty($platforms)) { // Only get platforms with existing caches so we don't build everything // if we don't need to $platforms = self::getPlatformsWithCaches(); } // Make sure the LanguageManager created modules cache is clear LanguageManager::resetCreatedModules(); //No need to build the cache if we can't store it if (static::$isCacheEnabled) { // Handle refreshing based on the cache part $method = 'rebuild' . ucfirst(strtolower($part)) . 'Cache'; foreach ((array) $platforms as $platform) { foreach (array(true, false) as $public) { $mm = MetaDataManager::getManager($platform, $public, true); if (method_exists($mm, $method)) { $contexts = static::getMetadataContexts($public, $params); // When a change occurs in the base metadata, we need to clear the cache for all contexts // except the ones we are going to rebuild in this request if (empty($params)) { $allContexts = array_filter(static::getAllMetadataContexts($public), function ($context) use($contexts) { foreach ($contexts as $current_context) { if ($current_context->getHash() === $context->getHash()) { return false; } } return true; }); foreach ($allContexts as $context) { $mm->deletePlatformVisibilityCaches($context); } } foreach ($contexts as $context) { $mm->{$method}($items, $context); } } } } } }