Example #1
0
        static void Main(string[] args)
        {
            DistributedCache.InitializeWith(new CacheProviderFactory(ConfigurationManager.AppSettings["DistributedCacheProvider"]));

            int max = 10000 * 100;

            string key = DateTime.Now.Ticks.ToString();

            //Parallel.For(1, 100000, t =>
            //{
            for (int t = 1; t <= max; t++)
            {
                DistributedCache.Add(string.Format("{1}_{0}", t, key), string.Format("daniel_{0}", t));
                Console.WriteLine(string.Format("Add {0} completed.", t));
            }
            Console.WriteLine("Add completed.");
            for (int t = 1; t <= max; t++)
            {
                DistributedCache.Remove(string.Format("{1}_{0}", t, key));
                Console.WriteLine(string.Format("Remove {0} completed.", t));
            }
            ;
            Console.WriteLine("Remove completed.");
            Console.ReadLine();
        }
Example #2
0
        public bool TestAdd(int sleepTimeInMilliseconds)
        {
            DistributedCache.Remove("mykey");

            DistributedCache.Add("mykey", new object(), DateTime.UtcNow.AddMilliseconds(sleepTimeInMilliseconds));

            //if (DistributedCache.Get<object>("mykey") == null)
            //    Trace.WriteLine("NOT INSERTED!!");

            bool worked = true;

            if (DistributedCache.Add("mykey", new object(), DateTime.UtcNow.AddMilliseconds(sleepTimeInMilliseconds)))
            {
                worked = false;
            }

            return(worked);
        }
Example #3
0
 /// <summary>
 /// 请求并接收指令中心的数据
 /// </summary>
 /// <param name="beatMessage"></param>
 /// <returns></returns>
 public BeatResult HeartBeat(BeatMessage beatMessage)
 {
     lock (_lockObj)
     {
         BeatResult beatResult = new BeatResult();
         beatResult.TaskList = new List <TaskMessage>();
         var tempList = _taskList.Where(t => t.TaskExecutor.Equals(beatMessage.HostIP) && t.Status == TaskMessageStatusEnum.None);
         foreach (var item in tempList)
         {
             var msg = MappingHelper.From <TaskMessage, TaskMessage>(item);
             beatResult.TaskList.Add(msg);
         }
         beatResult.Result = BeatResultEnum.Success;
         _taskList.Where(t => t.TaskExecutor.Equals(beatMessage.HostIP)).ToList()
         .ForEach(t => t.Status = TaskMessageStatusEnum.Executed);
         DistributedCache.Add(CacheKeys.InstuctionTaskListCacheKey, _taskList, DateTime.Now.AddYears(1));
         return(beatResult);
     }
 }
Example #4
0
        public ActionResult <IEnumerable <string> > Get()
        {
            //SmtpConfig
            //var connectionString = Config.GetConnectionString("SqlServer");

            //TblUser model = new TblUser()
            //{
            //	ID = Guid.NewGuid(),
            //	Name = "Young",
            //	DataCreated = DateTimeOffset.Now
            //};
            //access.DataAccess<TblUser> userDataAccess = new access.DataAccess<TblUser>(_context);
            //bool result = userDataAccess.Add(model);

            //if (result)
            //{
            //	model.Name = "Young+Lau";
            //	result = userDataAccess.Update(model);

            //	if (result)
            //	{
            //		model.Name = "Young+Lau+Hello,World";
            //		result = userDataAccess.Update(model, false, model.ID);

            //		if (result)
            //		{
            //			var m = userDataAccess.QueryByID(model.ID);

            //			if (m != null)
            //			{
            //				var lst = userDataAccess.QueryAll(t => t.ID != null);

            //				if (lst != null)
            //				{
            //					//
            //				}
            //			}
            //		}
            //	}
            //}
            //Assert.NotNull(model);
            //Assert.Equal(true, result);

            #region

            if (HttpContext.Session == null || !HttpContext.Session.IsAvailable)
            {
                HttpContext.Session.SetString("UserID", "1000");               //Microsoft.AspNetCore.Http
            }

            //添加
            bool booladd = cache.Add("id", "sssss");
            //验证
            bool boolExists = cache.Exists("id");
            //获取
            object obj = cache.Get("id");
            //删除
            bool boolRemove = cache.Remove("id");
            //修改
            bool boolModify = cache.Modify("id", "ssssssss");

            #endregion

            return(new string[] { "value1", "value2" });
        }