-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add controller examples to output caching doc (#32929)
- Loading branch information
Showing
20 changed files
with
544 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...core/performance/caching/output/samples/9.x/OCControllers/Controllers/CachedController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_oneendpoint> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache] | ||
public class CachedController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_oneendpoint> |
19 changes: 19 additions & 0 deletions
19
...etcore/performance/caching/output/samples/9.x/OCControllers/Controllers/EtagController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_etag> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache] | ||
public class EtagController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
var etag = $"\"{Guid.NewGuid():n}\""; | ||
HttpContext.Response.Headers.ETag = etag; | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_etag> |
18 changes: 18 additions & 0 deletions
18
.../performance/caching/output/samples/9.x/OCControllers/Controllers/EvictByTagController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_evictbytag> | ||
[ApiController] | ||
[Route("/[controller]/purge/{tag}")] | ||
[OutputCache] | ||
public class EvictByTagController : ControllerBase | ||
{ | ||
[HttpPost] | ||
public async Task PostAsync(IOutputCacheStore cache, string tag) | ||
{ | ||
await cache.EvictByTagAsync(tag, default); | ||
} | ||
} | ||
// </snippet_evictbytag> |
17 changes: 17 additions & 0 deletions
17
...re/performance/caching/output/samples/9.x/OCControllers/Controllers/Expire20Controller.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_selectpolicy> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache(PolicyName = "Expire20")] | ||
public class Expire20Controller : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_selectpolicy> |
17 changes: 17 additions & 0 deletions
17
...core/performance/caching/output/samples/9.x/OCControllers/Controllers/NoLockController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_selectnolock> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache(PolicyName = "NoLock")] | ||
public class NoLockController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_selectnolock> |
13 changes: 13 additions & 0 deletions
13
...e/performance/caching/output/samples/9.x/OCControllers/Controllers/NotCachedController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
[ApiController] | ||
[Route("/")] | ||
public class NotCachedController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...etcore/performance/caching/output/samples/9.x/OCControllers/Controllers/PostController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_post> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache(PolicyName = "CachePost")] | ||
public class PostController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_post> |
17 changes: 17 additions & 0 deletions
17
...tcore/performance/caching/output/samples/9.x/OCControllers/Controllers/QueryController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_selectquery> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache(PolicyName = "Query")] | ||
public class QueryController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_selectquery> |
17 changes: 17 additions & 0 deletions
17
...performance/caching/output/samples/9.x/OCControllers/Controllers/TagEndpointController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_tagendpoint> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache(Tags = new[] { "tag-blog", "tag-all" })] | ||
public class TagEndpointController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_tagendpoint> |
17 changes: 17 additions & 0 deletions
17
...performance/caching/output/samples/9.x/OCControllers/Controllers/VaryByValueController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.OutputCaching; | ||
|
||
namespace OCControllers.Controllers; | ||
|
||
// <snippet_selectquery> | ||
[ApiController] | ||
[Route("/[controller]")] | ||
[OutputCache(PolicyName = "VaryByValue")] | ||
public class VaryByValueController : ControllerBase | ||
{ | ||
public async Task GetAsync() | ||
{ | ||
await Gravatar.WriteGravatar(HttpContext); | ||
} | ||
} | ||
// </snippet_selectquery> |
Oops, something went wrong.