本文整理汇总了C#中ICacheManager.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ICacheManager.Dispose方法的具体用法?C# ICacheManager.Dispose怎么用?C# ICacheManager.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICacheManager
的用法示例。
在下文中一共展示了ICacheManager.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}