Open lesenro opened 6 years ago
Same question here. Is there a way to set ie. ClientTimeSpan in web.config's app settings and then use it as default value (for example in Global.asax or somewhere)? Anyway, it would be nice to still be able to override this value when setting CacheOutput's ClientTimeSpan attribute above action.
Late to the party but create an attribute that inherits from CacheOutputAttribute
and apply settings in OnActionExecuting
@evry-johan Can you please provide an example? Thank you in advance :)
@pedrocpinto Sure, this is how I do it. Just as in IsCachingAllowed
, you can get custom values in OnActionExecuting
:
public class CachedAttribute : CacheOutputAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
var maxAge = 86400;
ClientTimeSpan = maxAge;
ServerTimeSpan = maxAge;
base.OnActionExecuting(actionContext);
}
protected override bool IsCachingAllowed(HttpActionContext actionContext, bool anonymousOnly)
{
return base.IsCachingAllowed(actionContext, anonymousOnly) && ObjectFactory.GetInstance<ICacheManager>().EnableCache();
}
}
@evry-johan Thank you, that helped a lot 👍
Can i configure options in the web.config