protected override Task <IEnumerable <CacheItem <T> > > GetItemsAsync <T>(IEnumerable <string> keys, string partition) { if (!string.IsNullOrEmpty(partition)) { keys = keys.Select(key => $"${partition}$|{key}").ToList(); } return(Task.FromResult(_client.GetValues(keys, null).Select(pair => (CacheItem <T>)pair.Value).ToList().AsEnumerable())); }
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"); } }