Konrad
Konrad

Reputation: 4802

Refresh MemoryCache in C# Web API cyclically recurring

I have a Web API with an implemented MemoryCache in C#. This works quite well so far.

But the API is rarely accessed - and then almost every access is the first one that triggers the creation of the cache itself.

Due to the timeliness of the data, I can't let a cache live longer than 3 - 5 minutes.

Hence my question: I would like to call the 10 most recently accessed routes including query parameters cyclically - within the lifetime of a cache to keep it alive and up-to-date - and then when a "real" API request comes in, it can be answered directly from the then current cache.

Is that possible?

Upvotes: 0

Views: 16

Answers (0)

Related Questions