static CacheManager() { cacheDirectory = Lib.IOHelper.GetFileFullPath("Cache"); cacheKeyListFileName = Lib.IOHelper.GetFileFullPath(cacheDirectory + @"\" + "cacheKeyList"); _appCache = AppManager.GetServiceFromRoot <IMemoryCache>(); _redisApiClient = AppManager.GetServiceFromRoot <IRedisApiClient>(); if (!System.IO.Directory.Exists(cacheDirectory)) { System.IO.Directory.CreateDirectory(cacheDirectory); } if (!System.IO.File.Exists(cacheKeyListFileName)) { File.WriteAllText(cacheKeyListFileName, string.Empty); } else { var cacheItems = File.ReadAllLines(cacheKeyListFileName); foreach (var cacheItem in cacheItems) { var cacheInfo = cacheItem.Split('|'); cacheKeyList.Add(cacheInfo[0], cacheInfo[1]); } } }
private static TaskInfo NewTask(string cacheKey, ActionExecutingContext context, IRedisApiClient redisApiClient, ControllerActionDescriptor actionDescriptor, string remark) { var cacheResult = new TaskInfo() { CreateTime = DateTime.Now, UpdateTime = DateTime.Now, Remark = remark, TaskId = cacheKey }; redisApiClient.Set2(cacheKey, cacheResult, TimeSpan.FromDays(1)); Task.Run(async() => { //AppManager.CurrentAppContext.TaskId = cacheKey; await Task.Delay(1); try { var result = actionDescriptor.MethodInfo.Invoke(context.Controller, context.ActionArguments.Values.ToArray()); } catch (Exception ex) { Lib.Log.WriteExceptionLog($"NewTask Exception:{ex.Message} <br> StackTrace:{ex.StackTrace}"); } }); return(cacheResult); }