コード例 #1
0
        public void Can_Add_Multiple_And_Clear()
        {
            Cache.Clear();
            taskIdStrs.Clear();

            const int TaskCount = 1000;

            for (int i = 0; i < TaskCount; i++)
            {
                var task = new TaskCacheItem()
                {
                    IsDone  = false,
                    Summary = "Task " + i + " to cached.",
                    Data    = ArrayTool.GetRandomBytes(0x2000)
                };

                Cache.Add(task.Id.ToString(), task);
                taskIdStrs.Add(task.Id.ToString());
            }

            Assert.AreEqual(TaskCount, Cache.GetAllKeys().Count);

            foreach (var taskId in taskIdStrs)
            {
                Assert.IsNotNull(Cache.Get(taskId), "캐시에 해당 키의 정보가 없습니다. taskId=" + taskId);
            }
        }
コード例 #2
0
        public void Can_Add_And_Load_Task()
        {
            Cache.Clear();

            var task = new TaskCacheItem
            {
                IsDone  = false,
                Summary = @"Task to cached.",
                Data    = ArrayTool.GetRandomBytes(0x2000)
            };

            var taskId = task.Id.ToString();

            Cache.Add(taskId, task);
            taskIdStrs.Add(taskId);

            var tasks = Cache.GetAllKeys().Select(key => Cache.Get <TaskCacheItem>(key)).ToList();

            Assert.IsTrue(tasks.Any(t => t.IsDone == false));

            var retrieved = Cache.Get <TaskCacheItem>(taskId);

            Assert.IsNotNull(retrieved);
            Assert.AreEqual(taskId, retrieved.Id.ToString());

            Cache.Clear();

            if (Cache.GetAllKeys().Contains(taskId))
            {
                retrieved = Cache.Get(taskId) as TaskCacheItem;
                Assert.IsNull(retrieved);
            }
        }