现在的位置: 首页 > 综合 > 正文

缓存cache使用示例

2013年10月02日 ⁄ 综合 ⁄ 共 547字 ⁄ 字号 评论关闭

缓存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;
     }
}

 

【上篇】
【下篇】

抱歉!评论已关闭.