当前位置: 首页>>代码示例>>C#>>正文


C# ICacheManager.Remove方法代码示例

本文整理汇总了C#中ICacheManager.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheManager.Remove方法的具体用法?C# ICacheManager.Remove怎么用?C# ICacheManager.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICacheManager的用法示例。


在下文中一共展示了ICacheManager.Remove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Thread_Update

        public void Thread_Update(ICacheManager<object> cache)
        {
            using (cache)
            {
                var key = Guid.NewGuid().ToString();
                var handleInfo = string.Join("\nh: ", cache.CacheHandles.Select(p => p.Configuration.Name + ":" + p.GetType().Name));

                cache.Remove(key);
                cache.Add(key, new RaceConditionTestElement() { Counter = 0 });
                int numThreads = 5;
                int iterations = 10;
                int numInnerIterations = 10;
                int countCasModifyCalls = 0;

                // act
                ThreadTestHelper.Run(
                    () =>
                    {
                        for (int i = 0; i < numInnerIterations; i++)
                        {
                            cache.Update(key, (value) =>
                            {
                                var val = (RaceConditionTestElement)value;
                                val.Counter++;
                                Interlocked.Increment(ref countCasModifyCalls);
                                return value;
                            });
                        }
                    },
                    numThreads,
                    iterations);

                // assert
                Thread.Sleep(10);
                for (var i = 0; i < cache.CacheHandles.Count(); i++)
                {
                    var handle = cache.CacheHandles.ElementAt(i);
                    var result = (RaceConditionTestElement)handle.Get(key);
                    if (i < cache.CacheHandles.Count() - 1)
                    {
                        // only the last one should have the item
                        result.Should().BeNull();
                    }
                    else
                    {
                        result.Should().NotBeNull(handleInfo + "\ncurrent: " + handle.Configuration.Name + ":" + handle.GetType().Name);
                        result.Counter.Should().Be(numThreads * numInnerIterations * iterations, handleInfo + "\ncounter should be exactly the expected value.");
                        countCasModifyCalls.Should().BeGreaterOrEqualTo((int)result.Counter, handleInfo + "\nexpecting no (if synced) or some version collisions.");
                    }
                }
            }
        }
开发者ID:yue-shi,项目名称:CacheManager,代码行数:52,代码来源:ThreadRandomReadWriteTestBase.cs

示例2: TestEachMethod

        public static void TestEachMethod(ICacheManager<object> cache)
        {
            cache.Clear();

            cache.Add("key", "value", "region");
            cache.AddOrUpdate("key", "region", "value", _ => "update value", 22);

            cache.Expire("key", "region", TimeSpan.FromDays(1));
            var val = cache.Get("key", "region");
            var item = cache.GetCacheItem("key", "region");
            cache.Put("key", "put value");
            cache.RemoveExpiration("key");

            object update2;
            cache.TryUpdate("key", "region", _ => "update 2 value", out update2);

            object update3 = cache.Update("key", "region", _ => "update 3 value");

            cache.Remove("key", "region");

            cache.Clear();
            cache.ClearRegion("region");
        }
开发者ID:yue-shi,项目名称:CacheManager,代码行数:23,代码来源:Tests.cs

示例3: RandomRWTest

        public static void RandomRWTest(ICacheManager<Item> cache)
        {
            cache.Clear();

            const string keyPrefix = "RWKey_";
            const int actionsPerIteration = 104;
            const int initialLoad = 1000;
            int iterations = 0;
            int removeFails = 0;
            var keyIndex = 0;
            var random = new Random();

            Action create = () =>
            {
                if (keyIndex > 10000)
                {
                    keyIndex = initialLoad;
                }

                Interlocked.Increment(ref keyIndex);
                var key = keyPrefix + keyIndex;
                var newValue = Guid.NewGuid().ToString();
                var item = Item.Generate();

                cache.AddOrUpdate(key, item, p =>
                {
                    p.SomeStrings.Add(newValue);
                    return p;
                });
            };

            Action read = () =>
            {
                for (var i = 0; i < 100; i++)
                {
                    var val = cache.Get(keyPrefix + random.Next(1, keyIndex));
                }
            };

            Action remove = () =>
            {
                const int maxTries = 10;
                bool result = false;
                var tries = 0;
                string key;
                do
                {
                    tries++;
                    key = keyPrefix + random.Next(1, keyIndex);
                    result = cache.Remove(key);
                    if (!result)
                    {
                        Interlocked.Increment(ref removeFails);
                    }
                }
                while (!result && tries < maxTries);
            };

            Action report = () =>
            {
                while (true)
                {
                    Thread.Sleep(1000);
                    Console.WriteLine(
                        "Index is at {0} Items in Cache: {1} failed removes {4} runs: {2} \t{3}",
                        keyIndex,
                        cache.CacheHandles.First().Count,
                        iterations,
                        iterations * actionsPerIteration,
                        removeFails);

                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    foreach (var handle in cache.CacheHandles)
                    {
                        var stats = handle.Stats;
                        Console.WriteLine(string.Format(
                                "Items: {0}, Hits: {1}, Miss: {2}, Remove: {3} Adds: {4}",
                                    stats.GetStatistic(CacheStatsCounterType.Items),
                                    stats.GetStatistic(CacheStatsCounterType.Hits),
                                    stats.GetStatistic(CacheStatsCounterType.Misses),
                                    stats.GetStatistic(CacheStatsCounterType.RemoveCalls),
                                    stats.GetStatistic(CacheStatsCounterType.AddCalls)));
                    }

                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine();

                    iterations = 0;
                    removeFails = 0;
                }
            };

            for (var i = 0; i < initialLoad; i++)
            {
                create();
            }

            Task.Factory.StartNew(report);

            while (true)
//.........这里部分代码省略.........
开发者ID:yue-shi,项目名称:CacheManager,代码行数:101,代码来源:Tests.cs

示例4: CacheThreadTest

        public static void CacheThreadTest(ICacheManager<string> cache, int seed)
        {
            cache.Clear();

            var threads = 10;
            var numItems = 1000;
            var eventAddCount = 0;
            var eventRemoveCount = 0;
            var eventGetCount = 0;

            cache.OnAdd += (sender, args) => { Interlocked.Increment(ref eventAddCount); };
            cache.OnRemove += (sender, args) => { Interlocked.Increment(ref eventRemoveCount); };
            cache.OnGet += (sender, args) => { Interlocked.Increment(ref eventGetCount); };

            Func<int, string> keyGet = (index) => "key" + ((index + 1) * seed);

            Action test = () =>
            {
                for (int i = 0; i < numItems; i++)
                {
                    cache.AddOrUpdate(keyGet(i), i.ToString(), _ => i.ToString() + "update");
                }

                for (int i = 0; i < numItems; i++)
                {
                    if (i % 10 == 0)
                    {
                        cache.Remove(keyGet(i));
                    }
                }

                for (int i = 0; i < numItems; i++)
                {
                    string val = cache.Get(keyGet(i));
                }
            };

            Parallel.Invoke(new ParallelOptions() { MaxDegreeOfParallelism = 8 }, Enumerable.Repeat(test, threads).ToArray());

            foreach (var handle in cache.CacheHandles)
            {
                var stats = handle.Stats;
                Console.WriteLine(string.Format(
                        "Items: {0}, Hits: {1}, Miss: {2}, Remove: {3}, ClearRegion: {4}, Clear: {5}, Adds: {6}, Puts: {7}, Gets: {8}",
                            stats.GetStatistic(CacheStatsCounterType.Items),
                            stats.GetStatistic(CacheStatsCounterType.Hits),
                            stats.GetStatistic(CacheStatsCounterType.Misses),
                            stats.GetStatistic(CacheStatsCounterType.RemoveCalls),
                            stats.GetStatistic(CacheStatsCounterType.ClearRegionCalls),
                            stats.GetStatistic(CacheStatsCounterType.ClearCalls),
                            stats.GetStatistic(CacheStatsCounterType.AddCalls),
                            stats.GetStatistic(CacheStatsCounterType.PutCalls),
                            stats.GetStatistic(CacheStatsCounterType.GetCalls)));
            }

            cache.Dispose();

            Console.WriteLine(string.Format(
                "Event - Adds {0} Hits {1} Removes {2}",
                eventAddCount,
                eventGetCount,
                eventRemoveCount));
        }
开发者ID:yue-shi,项目名称:CacheManager,代码行数:63,代码来源:Tests.cs

示例5: DropCachedGroupsForUser

 /// <summary>
 /// Drops all the groups for a given user for all sites. This is called when a users groups has been updated
 /// </summary>
 /// <remarks>This should not be called if the caching model uses the distributes memcache solution</remarks>
 /// <param name="cache">The cache manager object you want to drop the user group from</param>
 /// <param name="userID">The id of the user you want to drop the cache for</param>
 /// <param name="siteID">The id of the site you want to drop the group for</param>
 static public void DropCachedGroupsForUser(ICacheManager cache, int userID, int siteID)
 {
     cache.Remove(_cacheName + userID.ToString() + "-" + siteID.ToString());
 }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:11,代码来源:UserGroups.cs

示例6: ClearAttributeData

 public static void ClearAttributeData(ICacheManager cache, string pluginName)
 {
     cache.Remove(pluginName+"@"+GetCacheKey());
 }
开发者ID:keep01,项目名称:efwplus_winformframe,代码行数:4,代码来源:EntityManager.cs

示例7: TestEachMethod

        public static void TestEachMethod(ICacheManager<object> cache)
        {
            cache.Clear();

            cache.Add("key", "value", "region");
            cache.AddOrUpdate("key", "region", "value", _ => "update value", new UpdateItemConfig(2, VersionConflictHandling.EvictItemFromOtherCaches));

            cache.Expire("key", "region", TimeSpan.FromDays(1));
            var val = cache.Get("key", "region");
            var item = cache.GetCacheItem("key", "region");
            cache.Put("key", "region", "put value");
            cache.RemoveExpiration("key", "region");

            object update2;
            cache.TryUpdate("key", "region", _ => "update 2 value", out update2);

            object update3 = cache.Update("key", "region", _ => "update 3 value");

            cache.Remove("key", "region");

            cache.Clear();
            cache.ClearRegion("region");
        }
开发者ID:serkanpektas,项目名称:CacheManager,代码行数:23,代码来源:Tests.cs

示例8: ClearAttributeData

 public static void ClearAttributeData(ICacheManager cache)
 {
     cache.Remove(GetCacheKey());
 }
开发者ID:keep01,项目名称:efwplus_winformframe,代码行数:4,代码来源:AbstractAttributeManager.cs

示例9: Thread_RandomAccess

        public void Thread_RandomAccess(ICacheManager<object> cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            foreach (var handle in cache.CacheHandles)
            {
                Trace.TraceInformation("Using handle {0}", handle.GetType());
            }

            var blob = new byte[1024];

            using (cache)
            {
                Action test = () =>
                {
                    var hits = 0;
                    var misses = 0;
                    var tId = Thread.CurrentThread.ManagedThreadId;

                    try
                    {
                        for (var r = 0; r < 5; r++)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                string key = "key" + i;
                                object value = blob.Clone();
                                string region = "region" + r;

                                CacheItem<object> item = null;
                                if (r % 2 == 0)
                                {
                                    item = new CacheItem<object>(key, value, ExpirationMode.Sliding, TimeSpan.FromMilliseconds(10));
                                }
                                else
                                {
                                    item = new CacheItem<object>(key, value, region, ExpirationMode.Absolute, TimeSpan.FromMilliseconds(10));
                                }

                                cache.Put(item);
                                if (!cache.Add(item))
                                {
                                    cache.Put(item);
                                }

                                var result = cache.Get(key);
                                if (result == null)
                                {
                                    misses++;
                                }
                                else
                                {
                                    hits++;
                                }

                                if (!cache.Remove(key))
                                {
                                    misses++;
                                }
                                else
                                {
                                    hits++;
                                }

                                Thread.Sleep(0);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("{1} Error: {0}", ex.Message, tId);
                        throw;
                    }

                    Trace.TraceInformation("Hits: {0}, Misses: {1}", hits, misses);
                };

                ThreadTestHelper.Run(test, 2, 1);
            }
        }
开发者ID:huoxudong125,项目名称:CacheManager,代码行数:83,代码来源:ThreadRandomReadWriteTestBase.cs


注:本文中的ICacheManager.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。