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();
         }
      }
    }

  • 相关阅读:
    Linux 共享库
    使用Visual Studio(VS)开发Qt程序代码提示功能的实现(转)
    ZOJ 3469 Food Delivery(区间DP)
    POJ 2955 Brackets (区间DP)
    HDU 3555 Bomb(数位DP)
    HDU 2089 不要62(数位DP)
    UESTC 1307 windy数(数位DP)
    HDU 4352 XHXJ's LIS(数位DP)
    POJ 3252 Round Numbers(数位DP)
    HDU 2476 String painter (区间DP)
  • 原文地址:https://www.cnblogs.com/xiaogelove/p/2014846.html
Copyright © 2011-2022 走看看