Is there a way to make cached requests not count for rate limit?

Hello there!

I have a service with proxy-cache activated, and I want to activate a rate limit too. Is there a way to configure this so the requests that hits the cache does not count for the rate limit?

For example. I configure a 5 request per minute limit. If a service makes 10 requests but 7 of them hits the cache, the service will only “consume” 3 requests from the rate-limit because the other 7 are answered by the cache.

I’m trying and can`t make it to work. It seems that the rate limit plugin has more priority than the cache one. I don’t know if this kind of behaviour can be configured in Kong.

Thanks!

Maybe you can try using rate limiting in front of the upstream service.

client -cache> Kong1 → Kong2 -rate limiting>upstream service

Kong2 can be a dbless deployment to keep minimum footprint.

Deploying more kong instances is a little too much.

I think that this is a Priority “issue”. The rate limit plugin is executed first, then the cache one:

RateLimitingHandler.PRIORITY = 901

local ProxyCacheHandler = {
VERSION = “1.3.2”,
PRIORITY = 100,
}

So, mayber I’ll try to fork the cache one and modify its priority to 902 or similar, and test if then the cache plugin executes first and the rate limit is not affected.

Kong has a tool for updating priority.

Check this out

I tried that, and modified the priority of the cache plugin to 902 (right above the rate-limit one that has 901).

It worked like a charm. Now if the request is already cached, it is not taken into account in the rate limit.

Thanks for the tool!


© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ