Ocelot
Ocelot copied to clipboard
Do Caching working on my setup ?
I have followed this part of the doc literally : https://ocelot.readthedocs.io/en/latest/features/caching.html
Then if I spam a request my first tough was to get a log like this :
ConnectionId:**OcRequestId** => RequestId:**OcRequestId**:00000001 RequestPath:/api/stats/collected
and get a response from this cached request for the number of time I set it up.
Instead I got something like :
Ocelot.Errors.Middleware.ExceptionHandlerMiddleware[0] => ConnectionId:0HLHK4OD3CE5E => RequestId:0HLHK4OD3CE5E:**00000004** RequestPath:/api/stats/collected
with the numbers that add up everytime... and the RequestIdKey
is random.
That also make me see that the limit rate that I setup doesn't work too... Does the GlobalConfiguration
part of my conf is working ?
ocelot.json
{
"GlobalConfiguration": {
"BaseUrl": "http://0.0.0.0:5000",
"RequestIdKey": "OcRequestId",
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "30s",
"PeriodTimespan": 1,
"Limit": 2
},
"AdministrationPath": "/administration"
},
"ReRoutes": [
{
"UpstreamPathTemplate": "/api/stats/collected",
"UpstreamHttpMethod": [
"Get"
],
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "blabla.azurewebsites.net",
"Port": 443
}
],
"DownstreamPathTemplate": "/v4/home/get",
"FileCacheOptions": { "TtlSeconds": 600, "Region": "stats" }
}
]
}
Startup.json
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Ocelot.Administration;
using Ocelot.Cache.CacheManager;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
namespace APIGateway.Base
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services
.AddOcelot(Configuration)
.AddCacheManager(c => { c.WithDictionaryHandle(); })
.AddAdministration("/administration", "XXXXXXXXX");
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//console logging
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseOcelot().Wait();
app.UseHttpsRedirection();
app.UseMvc();
}
}
}
Did I miss something ?
@gfelot I think the global configuration rate limiting stuff only applies if you are using dynamic routing. I think you need to set it per reroute.
I am confused by your issue, what is actually not working? Can you paste a full log?
Yes I put the caching configuration for each route and it's working now. But it cache the response only by the checking the url. On a POST if I modify the JSON body, Ocelot send me the last response.
That last part looks like a bug to me, converting this issue.
Yes I put the caching configuration for each route and it's working now. But it cache the response only by the checking the url. On a POST if I modify the JSON body, Ocelot send me the last response.
Do caching working in your setup ? if yes , pls help me i am not able flush the cache , please see this https://github.com/ThreeMammals/Ocelot/issues/1212
Please help ?
Is the caching outputted to the console when you say it's working?
Implemented and fixed by #889