/// <summary> /// Adds the current response to the cache if required /// Only stores by Path and stores the response in a dictionary. /// Do not use this as an actual cache :-) /// </summary> /// <param name="context">Current context</param> public void SetCache(NancyContext context) { if (context.Response.StatusCode != HttpStatusCode.OK) { return; } object cacheSecondsObject; if (!context.Items.TryGetValue(ContextExtensions.OUTPUT_CACHE_TIME_KEY, out cacheSecondsObject)) { return; } int cacheSeconds; if (!int.TryParse(cacheSecondsObject.ToString(), out cacheSeconds)) { return; } var cachedResponse = new CachedResponse(context.Response); this.cachedResponses[context.Request.Path] = new Tuple<DateTime, Response, int>(DateTime.Now, cachedResponse, cacheSeconds); context.Response = cachedResponse; }
/// <summary> /// Adds the current response to the cache if required /// Only stores by Path and stores the response in a dictionary. /// Do not use this as an actual cache :-) /// </summary> /// <param name="context">Current context</param> public void SetCache(NancyContext context) { if (context.Response.StatusCode != HttpStatusCode.OK) { return; } object cacheSecondsObject; if (!context.Items.TryGetValue(ContextExtensions.OUTPUT_CACHE_TIME_KEY, out cacheSecondsObject)) { return; } int cacheSeconds; if (!int.TryParse(cacheSecondsObject.ToString(), out cacheSeconds)) { return; } var cachedResponse = new CachedResponse(context.Response); this.cachedResponses[context.Request.Path] = new Tuple <DateTime, Response, int>(DateTime.Now, cachedResponse, cacheSeconds); context.Response = cachedResponse; }