本文整理汇总了C#中Cache.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Clear方法的具体用法?C# Cache.Clear怎么用?C# Cache.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanClear
public void CanClear()
{
var existing = new Dictionary<string, string>();
existing["Foo"] = "Bar";
var cache = new Cache<string, string>(existing);
cache.Count.ShouldBe(1);
cache.Clear();
cache.Count.ShouldBe(0);
}
示例2: TestCache
/// <exception cref="System.Exception"></exception>
public virtual void TestCache()
{
int retainCount = 1;
Cache cache = new Cache<string, Document>(retainCount);
IDictionary<string, object> props = new Dictionary<string, object>();
props.Put("foo", "bar");
Document doc1 = CreateDocumentWithProperties(database, props);
cache.Put(doc1.GetId(), doc1);
IDictionary<string, object> props2 = new Dictionary<string, object>();
props2.Put("foo2", "bar2");
Document doc2 = CreateDocumentWithProperties(database, props2);
cache.Put(doc2.GetId(), doc2);
NUnit.Framework.Assert.IsNotNull(cache.Get(doc1.GetId()));
NUnit.Framework.Assert.IsNotNull(cache.Get(doc2.GetId()));
cache.Remove(doc1.GetId());
NUnit.Framework.Assert.IsNull(cache.Get(doc1.GetId()));
cache.Clear();
NUnit.Framework.Assert.IsNull(cache.Get(doc2.GetId()));
}
示例3: FolderTest
public void FolderTest()
{
Cache cache = new Cache();
Folder folder = new Folder(null, "folder") {opaque_ref = "1"};
cache.AddFolder(new XenRef<Folder>(folder.opaque_ref),folder);
Assert.IsTrue(cache.Folders.Length==1);
Assert.AreEqual(folder,cache.Resolve(new XenRef<Folder>(folder.opaque_ref)));
Assert.AreEqual(folder,cache.Folders[0]);
//Check tryresolve
Folder result;
cache.TryResolve(new XenRef<Folder>(folder.opaque_ref), out result);
Assert.AreEqual(folder,result );
//Check Clear
cache.Clear();
Assert.IsTrue(cache.Folders.Length==0);
}
示例4: Clear_ShouldRemoveAll_Test
public void Clear_ShouldRemoveAll_Test()
{
Cache cache = new Cache();
cache.Add(TestKey, TestValue, new TimeSpan(0, 0, 1));
Assert.AreEqual(TestValue, cache.Get<string, string>(TestKey));
cache.Clear();
Assert.IsNull(cache.Get<string, string>(TestKey));
}