Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can i configure options in the web.config #235

Open
lesenro opened this issue Feb 9, 2018 · 5 comments
Open

Can i configure options in the web.config #235

lesenro opened this issue Feb 9, 2018 · 5 comments

Comments

@lesenro
Copy link

lesenro commented Feb 9, 2018

Can i configure options in the web.config

@Kraviecc
Copy link

Kraviecc commented Jul 5, 2018

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.

@evry-johan
Copy link

Late to the party but create an attribute that inherits from CacheOutputAttribute and apply settings in OnActionExecuting

@pedrocpinto
Copy link

@evry-johan Can you please provide an example? Thank you in advance :)

@evry-johan
Copy link

evry-johan commented Mar 18, 2021

@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();
        }
}

@pedrocpinto
Copy link

@evry-johan Thank you, that helped a lot 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants