Ejemplo n.º 1
0
        public ActionResult Index() {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage cache")))
                return new HttpUnauthorizedResult();

            var routeConfigurations = new List<RouteConfiguration>();
            var settings = Services.WorkContext.CurrentSite.As<CacheSettingsPart>();


            foreach (var routeProvider in _routeProviders) {
                // right now, ignore generic routes
                if (routeProvider.Value is StandardExtensionRouteProvider) continue;

                var routeCollection = routeProvider.Value.GetRoutes();
                var feature = routeProvider.Metadata["Feature"] as Orchard.Environment.Extensions.Models.Feature;

                // if there is no feature, skip route
                if (feature == null) continue;

                foreach (var routeDescriptor in routeCollection) {
                    var route = routeDescriptor.Route as Route;

                    if(route == null) {
                        continue;
                    }

                    // ignore admin routes
                    if (route.Url.StartsWith("Admin/") || route.Url == "Admin") continue;

                    var cacheParameterKey = _cacheService.GetRouteDescriptorKey(HttpContext, route);
                    var cacheParameter = _cacheService.GetCacheParameterByKey(cacheParameterKey);
                    var duration = cacheParameter == null ? default(int?) : cacheParameter.Duration;

                    routeConfigurations.Add(new RouteConfiguration {
                        RouteKey = cacheParameterKey,
                        Url = route.Url,
                        Priority = routeDescriptor.Priority,
                        Duration = duration,
                        FeatureName =
                            String.IsNullOrWhiteSpace(feature.Descriptor.Name)
                                ? feature.Descriptor.Id
                                : feature.Descriptor.Name
                    });
                }
            }

            var model = new IndexViewModel {
                DefaultCacheDuration = settings.DefaultCacheDuration,
                DefaultMaxAge = settings.DefaultMaxAge,
                VaryQueryStringParameters = settings.VaryQueryStringParameters,
                VaryRequestHeaders = settings.VaryRequestHeaders,
                IgnoredUrls = settings.IgnoredUrls,
                DebugMode = settings.DebugMode,
                ApplyCulture = settings.ApplyCulture,
                RouteConfigurations = routeConfigurations,
                IgnoreNoCache = settings.IgnoreNoCache
            };

            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult IndexPost() {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage cache")))
                return new HttpUnauthorizedResult();

            var model = new IndexViewModel {
                RouteConfigurations = new List<RouteConfiguration>()
            };

            if(TryUpdateModel(model)) {
                var settings = Services.WorkContext.CurrentSite.As<CacheSettingsPart>();
                settings.DefaultCacheDuration = model.DefaultCacheDuration;
                settings.DefaultMaxAge = model.DefaultMaxAge;
                settings.VaryQueryStringParameters = model.VaryQueryStringParameters;
                settings.VaryRequestHeaders = model.VaryRequestHeaders;
                settings.IgnoredUrls = model.IgnoredUrls;
                settings.DebugMode = model.DebugMode;
                settings.ApplyCulture = model.ApplyCulture;
                settings.IgnoreNoCache = model.IgnoreNoCache;

                // invalidates the settings cache
                _signals.Trigger(CacheSettingsPart.CacheKey);

                _cacheService.SaveCacheConfigurations(model.RouteConfigurations);

                Services.Notifier.Information(T("Cache Settings saved successfully."));
            }
            else {
                Services.Notifier.Error(T("Could not save Cache Settings."));
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 3
0
        public ActionResult IndexPost() {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("You do not have permission to manage output cache.")))
                return new HttpUnauthorizedResult();

            var model = new IndexViewModel {
                RouteConfigs = new List<CacheRouteConfig>()
            };

            if(TryUpdateModel(model)) {
                var settings = Services.WorkContext.CurrentSite.As<CacheSettingsPart>();
                settings.DefaultCacheDuration = model.DefaultCacheDuration;
                settings.DefaultCacheGraceTime = model.DefaultCacheGraceTime;
                settings.DefaultMaxAge = model.DefaultMaxAge;
                settings.VaryByQueryStringParameters = model.VaryByQueryStringParameters;
                settings.VaryByRequestHeaders = model.VaryByRequestHeaders;
                settings.IgnoredUrls = model.IgnoredUrls;
                settings.IgnoreNoCache = model.IgnoreNoCache;
                settings.VaryByCulture = model.VaryByCulture;
                settings.CacheAuthenticatedRequests = model.CacheAuthenticatedRequests;
                settings.VaryByAuthenticationState = model.VaryByAuthenticationState;
                settings.DebugMode = model.DebugMode;

                // Invalidate the settings cache.
                _signals.Trigger(CacheSettings.CacheKey);
                _cacheService.SaveRouteConfigs(model.RouteConfigs);

                Services.Notifier.Information(T("Output cache settings saved successfully."));
            }
            else {
                Services.Notifier.Error(T("Could not save output cache settings."));
            }

            return RedirectToAction("Index");
        }