zoukankan      html  css  js  c++  java
  • C# lock 用法和 缓存用法

    namespace LanVersionSwitch.Common
    {
      public class LanSwitch
      {

       private static readonly object obj = new object();

       public static string GetValue(string section, string key, string lan)
        {
          string filePath;
          if(HttpContext.Current.Cache[section + "_" + key + "_" + lan] == null)
            {
              lock (obj)
               {
                 if (HttpContext.Current.Cache[section + "_" + key + "_" + lan] == null)
                   {
                    if (lan.ToUpper() == "EN")
                     {
                       filePath =Environment.CurrentDirectory + "/" + System.Configuration.ConfigurationManager.AppSettings["filePathEn"].ToString();
                     }
                     else
                     {
                       filePath = Environment.CurrentDirectory + "/" + System.Configuration.ConfigurationManager.AppSettings["filePathCn"].ToString();
                     }
                       ManagerConfigIni mi = new ManagerConfigIni(filePath);
                       HttpContext.Current.Cache.Add(section + "_" + key + "_" + lan, mi.GetIniKeyValueForStr(section, key), null, DateTime.Now.AddSeconds(5), TimeSpan.Zero, CacheItemPriority.Normal, null);
                   }
               }
            }
           return HttpContext.Current.Cache[section + "_" + key + "_" + lan].ToString();
         }
      }
    }

  • 相关阅读:
    找工作经验之——面试(百度篇)
    找工作经验之——面试(微软实习篇)
    以下这个案例给我们什么启发?
    颈椎病
    柳传志写给部下的一封信,告诉你怎样被提拔
    马云:未来三十年会大动荡
    小米:如何用军事理论做商业
    诸葛亮最聪明,为何赢不了
    在最贵的地方点最便宜的菜
    改革有哪四大阻力
  • 原文地址:https://www.cnblogs.com/xiaogelove/p/2014846.html
Copyright © 2011-2022 走看看