Skip to content

Commit

Permalink
Update with more places for the http cache
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnwildermuth committed Jan 19, 2024
1 parent c0053e8 commit 8a08b88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/Apis/EmployeesApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Asp.Versioning;
using Mapster;
using Marvin.Cache.Headers;
using Marvin.Cache.Headers.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -26,16 +27,18 @@ public void Register(IEndpointRouteBuilder builder)
description: "Employees of the company that can create time tickets."));


group.MapGet("", GetAll);
group.MapGet("{id:int}", GetOne).WithName("GetOneEmployee");
group.MapGet("", GetAll)
.AddHttpCacheExpiration(maxAge: 1, noStore: true);
group.MapGet("{id:int}", GetOne)
.WithName("GetOneEmployee")
.AddHttpCacheExpiration(maxAge: 1, noStore: true);
group.MapPost("", Post);
group.MapPut("{id:int}", Update);
group.MapDelete("{id:int}", Delete);

}

// Get All
[HttpCacheExpiration(NoStore = true, MaxAge = 1)]
public static async Task<IResult> GetAll(BillingContext ctx)
{
var result = await ctx.Employees
Expand All @@ -46,7 +49,6 @@ public static async Task<IResult> GetAll(BillingContext ctx)
}

// Get One
[HttpCacheExpiration(NoStore = true, MaxAge = 1)]
public static async Task<IResult> GetOne(BillingContext ctx, int id)
{
var result = await ctx.Employees.FindAsync(id);
Expand Down
8 changes: 4 additions & 4 deletions src/Apis/TicketsApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Asp.Versioning;
using Mapster;
using Marvin.Cache.Headers;
using Marvin.Cache.Headers.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -29,17 +30,16 @@ public void Register(IEndpointRouteBuilder builder)

var theGet = group.MapGet("", GetAll);

group.MapGet("{id:int}", GetOne).WithName("GetOneTicket");
group.MapGet("{id:int}", GetOne).WithName("GetOneTicket")
.AddHttpCacheExpiration(cacheLocation: CacheLocation.Private, maxAge: 99999)
.AddHttpCacheValidation(mustRevalidate: true);
group.MapPost("", Post);
group.MapPut("{id:int}", Update);
group.MapDelete("{id:int}", Delete);

}

// Get All
//[HttpCacheIgnore]
[HttpCacheExpiration(CacheLocation = CacheLocation.Private, MaxAge = 99999)]
[HttpCacheValidation(MustRevalidate = true)]
public static async Task<IResult> GetAll(HttpContext http,
BillingContext ctx,
int page = 1,
Expand Down

0 comments on commit 8a08b88

Please sign in to comment.