private ViewPathResult ResolveUsingCache(
            bool useCache,
            ControllerContext context,
            string viewName,
            Func <ViewPathResult> resolve)
        {
            if (!useCache)
            {
                return(resolve());
            }

            var cacheKey = CreateCacheKey(context, viewName);

            var cachedLocation = ViewLocationCache.GetViewLocation(context.HttpContext, cacheKey);

            if (cachedLocation != null)
            {
                return(ViewPathResult.Create(cachedLocation));
            }

            var resolved = resolve();

            ViewLocationCache.InsertViewLocation(context.HttpContext, cacheKey, resolved.Path);
            return(resolved);
        }
        private ViewPathResult ResolveViewPath(ControllerContext controllerContext, string viewName, IEnumerable <string> formats)
        {
            if (IsSpecificPath(viewName))
            {
                return(ViewPathResult.Create(viewName));
            }

            var featurePath = GetFeaturePath(controllerContext);

            if (string.IsNullOrEmpty(featurePath))
            {
                return(ViewPathResult.Empty);
            }

            var controllerName = GetControllerName(controllerContext);
            var displayModes   = GetAvailableDisplayModesForContext(controllerContext);

            var searchLocations = formats
                                  .SelectMany(path => displayModes.Select(mode => FormatViewPath(path, featurePath, viewName, mode, controllerName)))
                                  .ToArray();
            var resolved = searchLocations.FirstOrDefault(viewPath => FileExists(controllerContext, viewPath)) ?? string.Empty;

            return(ViewPathResult.Create(resolved, searchLocations));
        }