开发者

Can I setup caching properties in the web.config?

开发者 https://www.devze.com 2023-03-26 04:23 出处:网络
Specifically for .NET 4.0, I will be using the System.Runtime.Caching namespace.Let\'s say all my methods will use sliding expiration with a duration of 20 minutes开发者_运维问答.Is it possible to pla

Specifically for .NET 4.0, I will be using the System.Runtime.Caching namespace. Let's say all my methods will use sliding expiration with a duration of 20 minutes开发者_运维问答. Is it possible to place this in a config file? If so, how would I go about doing that?

Thanks.


<appSettings>
    <add key="slidingExpirationInMinutes" value="20" />
</appSettings>

You can then grab this value and turn into an integer:

int cacheValue;
string cacheValueAsString = ConfigurationManager.AppSettings["slidingExpirationInMinutes"];
if(int.TryParse(cacheValueAsString, out cacheValue)
{
   //Set the value here
}
else
{
   //Fallback to default?
}

I assume you know how to set the sliding value through programatic means?

0

精彩评论

暂无评论...
验证码 换一张
取 消