GitXplorerGitXplorer
m

WebEssentials.AspNetCore.OutputCaching

public
52 stars
17 forks
11 issues

Commits

List of commits on branch master.
Verified
8bf5966a6f9e1a2604a55cdad56776575c5454d0

Merge pull request #29 from thompson-tomo/chore/#28_AddTFM

mmadskristensen committed 7 months ago
Verified
60cd11de79b12ca46e48b6db02765a65cb19c49e

Update appveyor.yml

tthompson-tomo committed 8 months ago
Verified
5215000b9f6548632bde9ce55d7ed99d11fcc0aa

Update appveyor.yml

tthompson-tomo committed 8 months ago
Verified
66220a71c283ff533104da909fb1be4d042f7885

Merge pull request #31 from thompson-tomo/chore/#30_MetadataUpdate

mmadskristensen committed 8 months ago
Unverified
fdddfa40ee9cf08f121f99148364179b5cf591e3

#30 update package metadata

tthompson-tomo committed 8 months ago
Unverified
01ccdaea75a5b926b01e6e1b93e5be0004edb8fe

Build updaye

tthompson-tomo committed 9 months ago

README

The README file for this repository.

ASP.NET Core output caching middleware

Build status NuGet

Server-side caching middleware for ASP.NET 2.0

Register the middleware

Start by registering the service it in Startup.cs like so:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddOutputCaching();
}

...and then register the middleware just before the call to app.UseMvc(...) like so:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseOutputCaching();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

Usage examples

There are various ways to use and customize the output caching. Here are some examples.

Action filter

Use the OutputCache attribute on a controller action:

[OutputCache(Duration = 600, VaryByParam = "id")]
public IActionResult Product()
{
    return View();
}

Programmatically

Using the EnableOutputCaching extension method on the HttpContext object in MVC, WebAPI or Razor Pages:

public IActionResult About()
{
    HttpContext.EnableOutputCaching(TimeSpan.FromMinutes(1));
    return View();
}

Caching profiles

Set up cache profiles to reuse the same settings.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddOutputCaching(options =>
    {
        options.Profiles["default"] = new OutputCacheProfile
        {
            Duration = 600
        };
    });
}

Then use the profile from an action filter:

[OutputCache(Profile = "default")]
public IActionResult Index()
{
    return View();
}