private ModuleViewLocationCacheResult LocatePageFromPath(string executingFilePath, string pagePath) { var applicationRelativePath = GetAbsolutePath(executingFilePath, pagePath); var cacheKey = new ModuleViewLocationCacheKey(applicationRelativePath, null); if (!ViewLookupCache.TryGetValue(cacheKey, out ModuleViewLocationCacheResult cacheResult)) { var expirationTokens = new HashSet <IChangeToken>(); cacheResult = CreateCacheResult(expirationTokens, applicationRelativePath); var cacheEntryOptions = new MemoryCacheEntryOptions(); cacheEntryOptions.SetSlidingExpiration(_cacheExpirationDuration); foreach (var expirationToken in expirationTokens) { cacheEntryOptions.AddExpirationToken(expirationToken); } // No views were found at the specified location. Create a not found result. if (cacheResult == null) { cacheResult = new ModuleViewLocationCacheResult(new[] { applicationRelativePath }); } cacheResult = ViewLookupCache.Set( cacheKey, cacheResult, cacheEntryOptions); } return(cacheResult); }
private ModuleViewLocationCacheResult OnCacheMiss( ViewLocationExpanderContext expanderContext, ModuleViewLocationCacheKey cacheKey) { IList <string> viewLocations = _options.ModuleViewLocationFormats; ModuleViewLocationCacheResult cacheResult = null; List <string> searchedLocations = new List <string>(); HashSet <IChangeToken> expirationTokens = new HashSet <IChangeToken>(); foreach (var location in viewLocations) { var path = string.Format( CultureInfo.InvariantCulture, location, expanderContext.ViewName, null); path = ModuleViewEnginePath.ResolvePath(path); cacheResult = CreateCacheResult(expirationTokens, path); if (cacheResult != null) { break; } searchedLocations.Add(path); } // No views were found at the specified location. Create a not found result. if (cacheResult == null) { cacheResult = new ModuleViewLocationCacheResult(searchedLocations); } var cacheEntryOptions = new MemoryCacheEntryOptions(); cacheEntryOptions.SetSlidingExpiration(_cacheExpirationDuration); foreach (var expirationToken in expirationTokens) { cacheEntryOptions.AddExpirationToken(expirationToken); } return(ViewLookupCache.Set(cacheKey, cacheResult, cacheEntryOptions)); }
private ModuleViewLocationCacheResult LocatePageFromViewLocations( ActionContext actionContext, string moduleViewName) { var expanderContext = new ViewLocationExpanderContext( actionContext, moduleViewName, null, null, null, false); Dictionary <string, string> expanderValues = null; var expanders = _options.ModuleViewLocationExpanders; var expandersCount = expanders.Count; if (expandersCount > 0) { expanderValues = new Dictionary <string, string>(StringComparer.Ordinal); expanderContext.Values = expanderValues; for (var i = 0; i < expandersCount; i++) { expanders[i].PopulateValues(expanderContext); } } var cacheKey = new ModuleViewLocationCacheKey( expanderContext.ViewName, expanderValues); if (!ViewLookupCache.TryGetValue(cacheKey, out ModuleViewLocationCacheResult cacheResult)) { cacheResult = OnCacheMiss(expanderContext, cacheKey); } return(cacheResult); }