缓存cache使用示例:
以下示例中将从web.config中读出一配置项存入缓存。
private string Config_WFServiceLogDir
{
get
{
string strKey = "Config_WFServiceLogDir";
string strLogDir = (string)(HttpContext.Current.Cache.Get(strKey));
if (strLogDir == null)
{
lock (this)
{
if (strLogDir == null)
{
try
{
strLogDir = System.Configuration.ConfigurationManager.AppSettings["WFService_Log_Dir"].ToString().Trim();
}
catch
{
strLogDir = "c:\\Example\\WFService_Log";
}
HttpContext.Current.Cache.Insert(strKey, strLogDir, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
}
}
}
return strLogDir;
}
}