本文整理汇总了C#中LruCache.Put方法的典型用法代码示例。如果您正苦于以下问题:C# LruCache.Put方法的具体用法?C# LruCache.Put怎么用?C# LruCache.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LruCache
的用法示例。
在下文中一共展示了LruCache.Put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LruCache_Get
public void LruCache_Get()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.IsNotNull(cache.Get(1));
Assert.IsNotNull(cache.Get(2));
}
示例2: LruCache_Contains
public void LruCache_Contains()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.IsTrue(cache.Contains(1));
Assert.IsTrue(cache.Contains(2));
Assert.IsFalse(cache.Contains(3));
}
示例3: LruCache_Clear
public void LruCache_Clear()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.AreEqual(2, cache.Count);
cache.Clear();
Assert.AreEqual(0, cache.Count);
}
示例4: LruCache_LeastUsedObjectIsRemovedWhenCapacityIsReached
public void LruCache_LeastUsedObjectIsRemovedWhenCapacityIsReached()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.IsNotNull(cache.Get(1));
Assert.IsNotNull(cache.Get(2));
Assert.AreEqual(2, cache.Count);
cache.Put(3, "Three");
Assert.AreEqual(2, cache.Count);
Assert.IsNull(cache.Get(1));
Assert.IsNotNull(cache.Get(2));
Assert.IsNotNull(cache.Get(3));
cache.Put(4, "Four");
Assert.AreEqual(2, cache.Count);
Assert.IsNull(cache.Get(2));
Assert.IsNotNull(cache.Get(3));
Assert.IsNotNull(cache.Get(4));
}
示例5: LruCache
public void GetとPutがスレッドセーフである()
{
LruCache lruCache = new LruCache(5, 1);
Action action1 = () => {
for (int i = 0; i < 1000 * 1000; i++)
{
lruCache.Put("a", "abc");
Assert.AreEqual("abc", lruCache.Get("a"));
}
};
Action action2 = () => {
for (int i = 0; i < 1000 * 1000; i++)
{
lruCache.Put("a", "abc");
Assert.AreEqual("abc", lruCache.Get("a"));
}
};
action1.BeginInvoke(null, null);
action2.BeginInvoke(null, null);
}
示例6: LruCache_MakeSureItemRemovedEventIsCalledWhenCacheIsDisposed
public void LruCache_MakeSureItemRemovedEventIsCalledWhenCacheIsDisposed()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
List<string> removedList = new List<string>();
cache.ItemRemoved += (o, s) => { removedList.Add(s.Item); };
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.AreEqual(0, removedList.Count);
cache.Dispose();
Assert.AreEqual(2, removedList.Count);
Assert.AreEqual("One", removedList[0]);
Assert.AreEqual("Two", removedList[1]);
}