Skip to content

Instantly share code, notes, and snippets.

@emrekizildas
Created November 21, 2020 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrekizildas/28830b07519020fe752a037924fd9c20 to your computer and use it in GitHub Desktop.
Save emrekizildas/28830b07519020fe752a037924fd9c20 to your computer and use it in GitHub Desktop.
Ocelot & Redis Caching on .NET 5.0 API Project
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddOcelot().AddCacheManager(x =>
{
x.WithRedisConfiguration("redis",
config =>
{
config.WithAllowAdmin()
.WithDatabase(0)
.WithEndpoint("localhost", 6379);
})
.WithJsonSerializer()
.WithRedisCacheHandle("redis");
});
}
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
await app.UseOcelot();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment