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

**URL:** <https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122>\
**Category:** Questions\
**Created:** [October 4, 2021, 9:00am UTC](https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122 "2021-10-04T09:00:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ander](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Ander](https://discuss.konghq.com/u/Ander)\
**Post date:** [October 4, 2021, 9:00am UTC](https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122/1 "2021-10-04T09:00:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![fomm](https://avatars.discourse-cdn.com/v4/letter/f/ea666f/32.png) [@fomm](https://discuss.konghq.com/u/fomm)\
**Post date:** [October 4, 2021, 11:07am UTC](https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122/2 "2021-10-04T11:07:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ander](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Ander](https://discuss.konghq.com/u/Ander)\
**Post date:** [October 6, 2021, 7:59am UTC](https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122/3 "2021-10-06T07:59:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fomm](https://avatars.discourse-cdn.com/v4/letter/f/ea666f/32.png) [@fomm](https://discuss.konghq.com/u/fomm)\
**Post date:** [October 6, 2021, 8:14am UTC](https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122/4 "2021-10-06T08:14:32Z")

</div>

Kong has a tool for updating priority.

> **[GitHub - Kong/priority-updater: Tool to quickly create a plugin with an...](https://github.com/Kong/priority-updater)**
>
> Tool to quickly create a plugin with an updated priority - GitHub - Kong/priority-updater: Tool to quickly create a plugin with an updated priority

Check this out

---

<div class="post-metadata">

**Author:** ![Ander](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Ander](https://discuss.konghq.com/u/Ander)\
**Post date:** [October 6, 2021, 11:30am UTC](https://discuss.konghq.com/t/is-there-a-way-to-make-cached-requests-not-count-for-rate-limit/9122/5 "2021-10-06T11:30:20Z")

</div>

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!
