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")); }
/// <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); }
public static string GetBBSStr(string str) { //int[] ic; string[] chars = CustomCache.Get("PersianChars") as string[]; //var ia = Ints(out ic); if (chars == null) { PersianChars(out chars); } bool flag = false; string strRes = ""; try { //str = Conversions.ToString(str.Trim()); //str = str.Trim(); //str = Rev(str); long num2 = str.Length; for (long i = num2; i > 0; i--) { string mid = Mid(str, (int)i, 1); var strTemp = Utility.Extention.SafeString(Asc(mid)); if (strTemp.SafeInt() < 0x80) { strTemp = mid; } else { strTemp = chars[strTemp.SafeInt()]; flag = true; } strRes += strTemp; } } catch (Exception) { throw; } if (flag) { return(NumRev(strRes)); } return(strRes); }
/// <summary> /// </summary> /// <param name="filter"></param> /// <returns></returns> public Domain.DTO.UserManagement GetUserInformationByUserName(BaseReportFilter <UserManagementEditFilter> filter) { try { var username = filter.ReportFilter?.UserName; BRule.Assert(!username.IsNullOrEmpty(), RuleExceptionCodeUserManagement.UserNameIsEmpty.GetEnumDescription(), (int)RuleExceptionCodeUserManagement.UserNameIsEmpty); var key = string.Format(pattern, username); var dtoCache = CustomCache.Get(key) as Domain.DTO.UserManagement; if (dtoCache != null) { return(dtoCache); } //var user = AuthenticationManager.AuthenticationProvider.UserManager.FindByName(username); //TODO //Mapper.CreateMap<IdentityModels.ApplicationUser, Domain.DTO.UserManagement>().ForMember(dest => dest.CreateDate, // opt => opt.MapFrom(src => src.CreateDate.ConvertMiladiToJalali())); //var model = Mapper.Map<IdentityModels.ApplicationUser, Domain.DTO.UserManagement>(user); var model = UserManagementService.GetUserByUserName(username); var party = PartyProvider.GetByUserName(username); if (party != null) { var branch = PartyBranchService.GetAll().FirstOrDefault(x => x.PartyId == party.Id && x.ValidUntil == null); if (branch?.BranchId != null) { if (branch?.BranchId != null) { model.BranchId = (int)branch?.BranchId; } } } model.RolesCodeList = AuthenticationManager.AuthenticationProvider.UserManager.GetRoles(model.Id).ToList(); CustomCache.Insert(key, model, 1200); return(model); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }
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); }
// 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()); }
public static string CorePath(string name) { var address = (Dictionary <string, string>)CustomCache.Get("Core.Addresses"); if (address != null) { return(address[name]); } address = new Dictionary <string, string>(); var doc = GetCoreXml(); var selectSingleNode = doc.SelectSingleNode("Address"); if (selectSingleNode != null) { foreach (XmlNode n in selectSingleNode.ChildNodes) { var physicalPath = PhysicalPath(n.InnerText); address.Add(n.Attributes["name"].Value, physicalPath); } } CustomCache.Insert("Core.Addresses", address); return(address[name]); }
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); } }