filipw / Strathweb.CacheOutput

ASP.NET Web API CacheOutput - library to allow you to cache the output of ApiControllers
Other
883 stars 254 forks source link

Dynamically determine cache duration #231

Open g2petter opened 6 years ago

g2petter commented 6 years ago

We have an action on a controller that normally shouldn't have any caching, but in a certain use case it's getting hammered a lot and it would be great to give it a cache of for example 5 seconds.

I know this could be solved by making two actions, one without caching and one with, but I was wondering if it's possible to set the cache duration as part of the request.

The idea is that when accessing /api/myController/myAction?id=1 you'd get a result back with no caching, but if you accessed /api/myController/myAction?id=1&cacheDuration=5 you'd set up 5 seconds of server cache for anyone accessing it with the cacheDuration=5 parameter.

Is this doable somehow?