{
bool expired = false;
CacheEntryRemovedReason reason = CacheEntryRemovedReason.CacheSpecificEviction;
- NameValueCollection config;
- int sleepPeriod;
-#if !DOTNET
- config = new NameValueCollection ();
- config.Add ("__MonoTimerPeriod", "1");
- sleepPeriod = 1100;
-#else
- config = null;
- sleepPeriod = 20100; // 20s is the .NET period - discovered by experimentation
-#endif
- var mc = new PokerMemoryCache ("MyCache", config);
+ int sleepPeriod = 1100;
+
+ var mc = new PokerMemoryCache ("MyCache");
var cip = new CacheItemPolicy ();
cip.RemovedCallback = (CacheEntryRemovedArguments args) => {
mc.Set ("key", "value", cip);
Thread.Sleep (sleepPeriod);
+ Assert.IsNull (mc.Get ("key"), "#A3-0");
Assert.IsTrue (expired, "#A3-1");
Assert.AreEqual (CacheEntryRemovedReason.Expired, reason, "#A3-2");
mc.Set ("key4", "value4", cip);
Thread.Sleep (sleepPeriod);
+ Assert.IsNull (mc.Get ("key1"), "#A4-1");
+ Assert.IsNull (mc.Get ("key2"), "#A4-2");
+ Assert.IsNull (mc.Get ("key3"), "#A4-3");
+ Assert.IsNotNull (mc.Get ("key4"), "#A4-4");
Assert.AreEqual (3, expiredCount, "#A4");
}
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, 1).ToString ();
- config["__MonoTimerPeriod"] = 1.ToString ();
using (var mc = new MemoryCache ("TestCacheShrink", config)) {
Assert.AreEqual (0, mc.GetCount (), "#CS1");
// wait for the cache thread to expire the short duration items, this will also shrink the size of the cache
global::System.Threading.Thread.Sleep (5 * 1000);
+ for (int i = 0; i < HEAP_RESIZE_SHORT_ENTRIES; i++) {
+ Assert.IsNull (mc.Get ("short-" + i), "#CS4-" + i);
+ }
Assert.AreEqual (HEAP_RESIZE_LONG_ENTRIES, mc.GetCount (), "#CS4");
// add some new items into the cache, this will grow the cache again
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 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, 1).ToString ();
- config["__MonoTimerPeriod"] = 1.ToString ();
using (var mc = new MemoryCache ("TestCacheExpiryOrdering", config)) {
Assert.AreEqual (0, mc.GetCount (), "#CEO1");
global::System.Threading.Thread.Sleep (4 * 1000);
+ for (int i = 0; i < 100; i++) {
+ Assert.IsNull (mc.Get ("short-" + i), "#CEO4-" + i);
+ }
Assert.AreEqual (100, mc.GetCount (), "#CEO4");
}
}
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, 1).ToString ();
- config["__MonoTimerPeriod"] = 1.ToString ();
using (var mc = new MemoryCache ("TestCacheSliding", config)) {
Assert.AreEqual (0, mc.GetCount (), "#CSL1");
Assert.AreNotEqual (null, item, "#CSL3-" + i);
}
+ Assert.IsNull (mc.Get ("expire1"), "#CSL4-1");
+ Assert.IsNull (mc.Get ("expire2"), "#CSL4-2");
+ Assert.IsNull (mc.Get ("expire3"), "#CSL4-3");
+ Assert.IsNull (mc.Get ("expire4"), "#CSL4-4");
+ Assert.IsNull (mc.Get ("expire5"), "#CSL4-5");
Assert.AreEqual (1, mc.GetCount (), "#CSL4");
global::System.Threading.Thread.Sleep (4 * 1000);
+ Assert.IsNull (mc.Get ("slidingtest"), "#CSL5a");
Assert.AreEqual (0, mc.GetCount (), "#CSL5");
}
}