Esempio n. 1
0
        private List <string> GetUploadFileTypes()
        {
            if (CustomCache.Get("supported-upload-types") == null)
            {
                CustomCache.Add("supported-upload-types", this.dictionaryBusiness.GetDictionary("supported-upload-types", "json"));
            }

            return((List <string>)CustomCache.Get("supported-upload-types"));
        }
Esempio n. 2
0
        /// <summary>
        /// Read addressed from txt file
        /// </summary>
        /// <returns>List of strings</returns>
        public List <string> GetAllAddresses()
        {
            var addressList = new List <string>();

            try
            {
                string cacheKey = CustomCache.GetCacheKey(AddressConstant.AddressCacheKey).ToString();
                if (CustomCache.Exists(cacheKey))
                {
                    CustomCache.Get(cacheKey, out addressList);
                    if (addressList == null)
                    {
                        CustomCache.Clear(cacheKey);
                    }
                }
                if (!CustomCache.Exists(cacheKey))
                {
                    string filePath = HttpContext.Current.Server.MapPath(AddressConstant.CSVLocation);
                    if (!string.IsNullOrWhiteSpace((filePath)))
                    {
                        using (StreamReader reader = new StreamReader(filePath))
                        {
                            while (!reader.EndOfStream)
                            {
                                if (!string.IsNullOrWhiteSpace(reader.ReadLine()))
                                {
                                    string address = reader.ReadLine().Trim();
                                    if (!string.IsNullOrWhiteSpace(address))
                                    {
                                        addressList.Add(address);
                                    }
                                }
                            }
                        }
                    }
                    if (addressList != null && addressList.Count > 0)
                    {
                        CustomCache.Add(addressList, cacheKey, Convert.ToDouble(AddressConstant.CacheDurantion));
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return(addressList);
        }
Esempio n. 3
0
        public static bool HasSpottedBuff(AIHeroClient unit)
        {
            if (MenuManager.IsCacheEnabled && HasBuff.Exist(unit.NetworkId))
            {
                return(HasBuff[unit.NetworkId]);
            }

            var hasBuff = unit.Buffs.Any(
                b => b.IsActive && string.Equals(b.Name, "jhinespotteddebuff", StringComparison.InvariantCultureIgnoreCase));

            if (MenuManager.IsCacheEnabled)
            {
                HasBuff.Add(unit.NetworkId, hasBuff);
            }

            return(hasBuff);
        }
Esempio n. 4
0
        public object GetDictionary(string dictionaryType, string outputFormat)
        {
            Logger.Info("Entering GetDictionary");

            object results = null;

            if (CustomCache.Get(dictionaryType) == null)
            {
                results = this.dictionaryBusiness.GetDictionary(dictionaryType, outputFormat);
                CustomCache.Add(dictionaryType, results);
            }
            else
            {
                results = CustomCache.Get(dictionaryType);
            }
            Logger.Debug("Logging CustomCache for dictionaryType");
            Logger.Info("Exiting GetDictionary");
            return(results);
        }
Esempio n. 5
0
        // GET: Cache
        public ActionResult Index()
        {
            //自己实现缓存


            for (int i = 0; i < 5; i++)
            {
                string key     = string.Format("{0}_{1}_{2}", "Program", "Count", 13);
                int    iResult = 0;
                if (CustomCache.Exist(key))
                {
                    iResult = CustomCache.Get <int>(key);
                }
                else
                {
                    iResult = Count(13);
                    CustomCache.Add(key, iResult);
                }

                Console.WriteLine("这里是第{0}次获取数据,结果为{1}", i, Count(12));
            }

            //使用内置缓存类方法如下:
            {
                string CacheKey = "CacheKey001";
                if (CacheHelper.IsCache(CacheKey))//判断缓存是否存在
                {
                    int a = 0;
                    a = CacheHelper.GetCaChe <int>(CacheKey);//获取缓存
                }
                else
                {
                    CacheHelper.CacheOjbectLocak <int>(1, CacheKey, 0);//存入缓存
                }
            }

            return(View());
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            try
            {
                {
                    //{
                    //    for (int i = 0; i < 5; i++)
                    //    {
                    //    Console.WriteLine($"Obtain {nameof(DBHelper)} for {i} times {DateTime.Now.ToString("yyyyMMdd HHmmss.fff")}");
                    //    List<Program> programList = null;
                    //    string key = $"{nameof(DBHelper)}_Query_{nameof(Program)}_{123}";

                    //        //Encapusulate this part by delegation.
                    //        //if (!CustomCache.Exist(key))
                    //        //{
                    //        //    programList = DBHelper.Query<Program>(123);
                    //        //    CustomCache.Add(key, programList);
                    //        //}
                    //        //else
                    //        //{
                    //        //    programList = CustomCache.Get<List<Program>>(key);
                    //        //}

                    //        programList = CustomCache.FindOrAdd(key, () => DBHelper.Query<Program>(123));
                    //        Console.WriteLine($"The {i} time you fetch the data is {programList.GetHashCode()}");
                    //    }
                    //}
                    //{
                    //    for (int i = 0; i < 5; i++)
                    //    {
                    //    Console.WriteLine($"Obtain {nameof(FileHelper)} for {i} times {DateTime.Now.ToString("yyyyMMdd HHmmss.fff")}");
                    //    List<Program> programList = null;
                    //    Console.WriteLine("==FileHelper==");
                    //        string key = $"{nameof(FileHelper)}_Query_{nameof(Program)}_456";
                    //        programList = CustomCache.FindOrAdd(key, () => (FileHelper.Query<Program>(456)));
                    //        Console.WriteLine($"The {i} time you fetch the data is {programList.GetHashCode()}");
                    //    }
                    //}
                    //{
                    //    for (int i = 0; i < 5; i++)
                    //    {
                    //    Console.WriteLine($"Obtain {nameof(RemoteHelper)} for {i} times {DateTime.Now.ToString("yyyyMMdd HHmmss.fff")}");
                    //    List<Program> programList = null;
                    //    Console.WriteLine("==RemoteHelper==");
                    //        string key = $"{nameof(RemoteHelper)}_Query_{nameof(Program)}_456";
                    //        programList = CustomCache.FindOrAdd(key, () => (RemoteHelper.Query<Program>(456)));
                    //        Console.WriteLine($"The {i} time you fetch the data is {programList.GetHashCode()}");
                    //    }
                    //}
                }

                //Handle the issue of data in chache changed.
                //E.g. User authorities, user->role->menu, generally stable, suit to use chache.
                //1. When a user's authorities changed, just remove it.
                {
                    //2. When a menu is changed, should not go through the whole cache or delete all , just delete the items
                    // which are relavent to the menu
                    //string key = "_System_Menu";
                    //CustomCache.RemoveCondition(s => s.Contains("_Menu_"));
                }

                {
                    //Add a time attribute to the cache data.
                    //Veryfy the validaty of cached data in an active and passive manner.
                    Console.WriteLine("===Set period of out of date of an item===");
                    string key = "_System_Menu";
                    if (CustomCache.Exist(key))
                    {
                        string result = CustomCache.Get <string>(key);
                    }
                    else
                    {
                        string result = "New item";
                        CustomCache.Add(key, result, 10);
                    }

                    //As long as the data source has changed or not during the validity period, the cache will prevail
                    if (CustomCache.Exist(key))
                    {
                        string result = CustomCache.Get <string>(key);
                    }
                    else
                    {
                        string result = "New item";
                        CustomCache.Add(key, result, 5);
                    }

                    Thread.Sleep(5000);
                    //As long as the data is expired, regardless of whether the data source has changed or not, reacquire it
                    if (CustomCache.Exist(key))
                    {
                        string result = CustomCache.Get <string>(key);
                    }
                    else
                    {
                        string result = "New item";
                        CustomCache.Add(key, result, 5);
                    }
                }



                Console.Read();
            }catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }