/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="next"></param> /// <returns></returns> public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next) { var settings = new HttpCacheSettings() { Expiry = ConfiguredExpiry }; if (_options.EnableConfiguration) { settings = GetConfigSettings(context, settings); } if (!settings.Enabled) { await next(); return; } var pipa = new CachingPipeline(_validator, CacheDirectiveProvider, _options) { ApplyNoCacheNoStoreForNonCacheableResponse = ApplyNoCacheNoStoreForNonCacheableResponse, ConfiguredExpiry = settings.Expiry }; var carryon = await pipa.Before(context.HttpContext); if (!carryon) // short-circuit { return; } var execCtx = await next(); // _______________________________________________________________________________ var or = execCtx.Result as ObjectResult; await pipa.After(context.HttpContext, or == null || or.Value == null?null : or.Value); }
private HttpCacheSettings GetConfigSettings(ResourceExecutingContext context, HttpCacheSettings settings) { const string ControllerKey = "controller"; const string ActionKey = "action"; if (!context.RouteData.Values.ContainsKey(ControllerKey) || !context.RouteData.Values.ContainsKey(ActionKey)) { return(settings); } var key = $"CacheCow:{context.RouteData.Values[ControllerKey]}:{context.RouteData.Values[ActionKey]}"; var section = _config.GetSection(key); if (section.Exists()) { section.Bind(settings); } return(settings); }