Cache not clearing, what am I missing?
Does anyone know why this cache is not clearing?
I am trying to implement simple rate limiting an and old MVC application. If a POST endpoint is hit too many times, return a 500/429.
My approach:
This cache item never expires. The same thing happens if I am using the HttpContext cache approach:
...
etc.
Any idea?
I am testing this by running an external script that hits the end point multiple times. I can trigger the rejection, but the cache never clears, so the limiting/blocking always remains in place.
1 Reply
Still not sure what's going on here. I0 am guessing the cache resets or adds time somehow every time I update the hitCount, it is my understanding that shouldn't be the case.
I've just created a second cache item and that tracks the same expiry time. This one clears as expected, so if it's empty I can reset the original cache item (doesn't matter if has become null at that point as a new one is just created):