NuGet package | Owin.Framework.OutputCache |
GitHub source | OwinFramework.OutputCache |
This middleware will improve the performance of your web site by capturing the output from downstream middleware and saving it in the ICache facility, then using the cached response when another identical request is received.
The output is only cached when dwnstream middleware indicates that it is valid to cache the response. Other Middleware (like the static file middleware) will communicate with the output cache when installed to tell it when the response can be cached.
Downstream middleware can set a category and a priority in the output cache for each request. The output cache can be configured with different cache behavours for all combinations of these two values.
builder.Register(ninject.Get<OwinFramework.OutputCache.OutputCacheMiddleware>()) .As("Output cache") .ConfigureWith(config, "/owinFramework/middleware/outputCache");
The configuration below is the configuration you will get by default if you do not provide a configuration for this middleware.
{ "owinFramework": { "middleware": { "outputCache": { "documentationRootUrl": "/outputCache", "rules": null } } } }
The output cache middleware must have rules defined before it will cache anything. The rules define what kind of caching to apply to each type of content that can be requested from your website.
When downstream middleware indicates that caching is possible on the content that it is producing, it passes back a "Category" and "Priority" to the output cache. In the output cache rules you can match on one, both or neither of these and define the caching behavior.
Below is an example configuration that provides some caching:
{ "owinFramework": { "middleware": { "outputCache": { "documentationRootUrl": "/outputCache", "rules": [ { "category": "UserProfile", "priority": "High", "cacheCategory": "Shared", "serverCacheTime": "00:30:00", "browserCacheTime": "00:10:00" }, { "category": "Product", "priority": "Always", "cacheCategory": "Local", "serverCacheTime": "01:00:00", "browserCacheTime": "00:30:00" }, { "category": "Product", "priority": "Medium", "cacheCategory": "Local", "serverCacheTime": "00:10:00", "browserCacheTime": "2" } ] } } } }