Пример #1
0
        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);
        }
Пример #2
0
        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));
        }