Skip to content
Permalink
Browse files

ResponseCaching WebAPI

  • Loading branch information
ignatandrei committed Jan 19, 2020
1 parent 2bde813 commit b8d38658b5135e4d3c93da78f77ffb9f01376829
@@ -18,6 +18,7 @@ namespace InfoValutarWebAPI.Controllers
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/rates")]
[ApiController]
[ResponseCache(CacheProfileName = "Default30")]
public class FromDBController : ControllerBase
{
private readonly IRetrieve retrieve;
@@ -30,6 +30,7 @@ public class LastCommitInfo
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/info")]
[ResponseCache(CacheProfileName = "Default1Day")]
public class InfoController
{
/// <summary>
@@ -14,6 +14,7 @@ namespace InfoValutarWebAPI.Controllers
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/save")]
[ApiController]
[ResponseCache(CacheProfileName = "Default30")]
public class LoadSaveDataController : ControllerBase
{
/// <summary>
@@ -15,6 +15,7 @@ namespace InfoValutarWebAPI.Controllers
[ApiController]
[ApiVersion( "1.0" )]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ResponseCache(CacheProfileName = "Default30")]
public class TodayRates : ControllerBase
{
private readonly ILogger<TodayRates> _logger;
@@ -33,6 +33,7 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCaching();
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "wwwroot";
@@ -49,7 +50,19 @@ public void ConfigureServices(IServiceCollection services)
});

});
services.AddControllers();
services.AddControllers(c=>
{
c.CacheProfiles.Add("Default30",
new CacheProfile()
{
Duration = 30
});
c.CacheProfiles.Add("Default1Day",
new CacheProfile()
{
Duration = 60*60*24
});
});
services.AddSingleton<LoadExchangeProviders>(new LoadExchangeProviders("plugins"));
services.AddSingleton<InMemoryDB>();

@@ -108,7 +121,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseStaticFiles();

app.UseRouting();

app.UseResponseCaching();
app.UseAuthorization();

app.UseOpenApi();

0 comments on commit b8d3865

Please sign in to comment.
You can’t perform that action at this time.