本文整理汇总了C#中System.Runtime.Caching.MemoryCache.GetValues方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryCache.GetValues方法的具体用法?C# MemoryCache.GetValues怎么用?C# MemoryCache.GetValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Caching.MemoryCache
的用法示例。
在下文中一共展示了MemoryCache.GetValues方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestExpiredGetValues
public void TestExpiredGetValues ()
{
var config = new NameValueCollection ();
config["cacheMemoryLimitMegabytes"] = 0.ToString ();
config["physicalMemoryLimitPercentage"] = 100.ToString ();
config["__MonoEmulateOneCPU"] = true.ToString ();
// it appears that pollingInterval does nothing, so we set the Mono timer as well
config["pollingInterval"] = new TimeSpan (0, 0, 10).ToString ();
config["__MonoTimerPeriod"] = 10.ToString ();
using (var mc = new MemoryCache ("TestExpiredGetValues", config)) {
Assert.AreEqual (0, mc.GetCount (), "#EGV1");
var keys = new List<string> ();
// add some short duration entries
for (int i = 0; i < 10; i++) {
var key = "short-" + i;
var expireAt = DateTimeOffset.Now.AddSeconds (1);
mc.Add (key, i.ToString (), expireAt);
keys.Add (key);
}
Assert.AreEqual (10, mc.GetCount (), "#EGV2");
global::System.Threading.Thread.Sleep (1000);
// we have waited but the items won't be expired by the timer since it wont have fired yet
Assert.AreEqual (10, mc.GetCount (), "#EGV3");
// calling GetValues() will expire the items since we are now past their expiresAt
mc.GetValues (keys);
Assert.AreEqual (0, mc.GetCount (), "#EGV4");
}
}