Can I setup caching properties in the web.config?
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?
精彩评论