I need to set the Cache Duration within the controller or set something that can be used by a cache policy to set the ResponseExpirationTimeSpan. (How long the data can be cached varies based on the situation)
I am not using minimal API.
I tried setting the expiry value via httpContext and picking it up in a policy. eg.
HttpContext.Items["cacheExpire"] = 2;
but
IOutputCachePolicy.CacheRequestAsync & IOutputCachePolicy.ServeFromCacheAsync
gets called before the controller method and setting it in IOutputCachePolicy.ServeResponseAsync does not take effect.
What is the correct solution for this scenario?
To set the cache duration in a controller, get the
IOutputCacheFeatureand set the time on it.example: