示例#1
0
        public async Task RemoveByPrefixTest()
        {
            var eventPublisher = new Mock <IMediator>();

            MemoryCacheManager memoryCacheManager = new MemoryCacheManager(new MemoryCache(new MemoryCacheOptions {
            }), eventPublisher.Object);
            await memoryCacheManager.SetAsync("exampleKey025", 5, int.MaxValue);

            await memoryCacheManager.SetAsync("exampleKey026", 5, int.MaxValue);

            await memoryCacheManager.SetAsync("exampleKey027", 5, int.MaxValue);

            await memoryCacheManager.SetAsync("exampleKey127", 5, int.MaxValue);

            string pattern = @"exampleKey0";
            await memoryCacheManager.RemoveByPrefix(pattern);

            Assert.IsFalse(memoryCacheManager.IsSet("exampleKey025"));
            Assert.IsFalse(memoryCacheManager.IsSet("exampleKey026"));
            Assert.IsFalse(memoryCacheManager.IsSet("exampleKey027"));
            Assert.IsTrue(memoryCacheManager.IsSet("exampleKey127"));
        }
示例#2
0
        public async Task RemoveByPatternTest()
        {
            /*
             * In this test I provide:
             *  1. pattern that consists of "key100\d" which matchs to: key1009, but not to key1010
             *  2. ICacheManager object with several keys
             *  3. List<string> with several keys
             */
            var eventPublisher = new Mock <IMediator>();

            ICacheManager icacheManager = new MemoryCacheManager(new MemoryCache(new MemoryCacheOptions {
            }), eventPublisher.Object);
            await icacheManager.SetAsync("key1001", 33, int.MaxValue);

            await icacheManager.SetAsync("key1202", 1244, int.MaxValue);

            await icacheManager.SetAsync("key1003", 512, int.MaxValue);

            await icacheManager.SetAsync("key1204", 55, int.MaxValue);

            await icacheManager.SetAsync("key1005", 32, int.MaxValue);

            string pattern = @"key100\d"; //"key100" and one digit

            List <string> keys = new List <string>();

            keys.Add("key1001");
            keys.Add("key1202");
            keys.Add("key1003");
            keys.Add("key1204");
            keys.Add("key1005");

            await icacheManager.RemoveByPrefix(pattern);

            Assert.IsNotNull(icacheManager.GetAsync <int>("key1202"));
            Assert.IsNotNull(icacheManager.GetAsync <int>("key1204"));
        }