Open NanditaReshamwala opened 7 years ago
You should be using Redis or another cache service in production. Implementing a Redis repo is a trivial task, all you need to do is SET/GET the key same way is being done here. You don't need to implement Clear
.
hi Stefanprodan,
Thank you for your reply. I am thinking to use builtin cache repository. To work around issues on restarting application, I am thinking to save throttling counter to db on shut down of the application and reload it in cache on startup. For this, I need to know the cache id WebApiThrottle use, is there any way to figure it out?
Second question is , after application restart, would inbuilt logic read restored throttlecounter from the cache if it is already restored in the cache on application startup?
kind regards, Nandita Reshamwala
Hi @NanditaReshamwala did you ever implement a custom cache repository?
Hi @stefanprodan, a question - I'm also looking to do this with Memcached/Redis as a backend, but neither of those support Sliding Expiration. I noticed that the Save
method does make use of a sliding expiration. I assume a sliding expiration is necessary when we implement our own IThrottleRepository
, right?
Memcached/Redis don't really have a sliding expiration concept, and one way of sorta-kinda emulating this is to get the object out, then set it again with the same original timespan - but the FirstOrDefault
method simply requests by id, the important missing piece is the timespan.
Any code or advice shared here would be appreciated!
@NanditaReshamwala @stefanprodan When using redis, how to update the throttleCounter???
hi three,
I'm using in built CacheRepository() in throttling handler. As explained in the documentation, it uses ASP.NET Cache when hosted in IIS. If we restart web application then the counter is resets to 0 because it uses ASP.NET cache. Document suggests to create customised repository using IThrottleRepository interface.
Is there any example of implementation of IThrottleRepository that can provide some guidelines tome how that can be customised?
kind regards, Nandita