public async Task CacheNone() { using (ScopedLocalServiceOverride <IAmbientCache> localCache = new ScopedLocalServiceOverride <IAmbientCache>(null)) { TestCache ret; AmbientCache <TestCache> cache = new AmbientCache <TestCache>(); await cache.Store(true, "Test1", this); ret = await cache.Retrieve <TestCache>("Test1"); Assert.IsNull(ret); await cache.Remove <TestCache>(true, "Test1"); ret = await cache.Retrieve <TestCache>("Test1", null); Assert.IsNull(ret); await cache.Clear(); ret = await cache.Retrieve <TestCache>("Test1", null); Assert.IsNull(ret); } }
public async Task CacheSpecifiedImplementation() { AmbientSettingsOverride localSettingsSet = new AmbientSettingsOverride(TestCacheSettingsDictionary, nameof(CacheSpecifiedImplementation)); using (AmbientClock.Pause()) using (new ScopedLocalServiceOverride <IAmbientSettingsSet>(localSettingsSet)) { TestCache ret; IAmbientCache cacheService = new BasicAmbientCache(localSettingsSet); AmbientCache <TestCache> cache = new AmbientCache <TestCache>(cacheService, "prefix"); await cache.Store <TestCache>(true, "Test1", this); ret = await cache.Retrieve <TestCache>("Test1", null); Assert.AreEqual(this, ret); await cache.Remove <TestCache>(true, "Test1"); ret = await cache.Retrieve <TestCache>("Test1", null); Assert.IsNull(ret); await cache.Store <TestCache>(true, "Test2", this, null, DateTime.MinValue); ret = await cache.Retrieve <TestCache>("Test2", null); Assert.AreEqual(this, ret); await Eject(cache, 1); ret = await cache.Retrieve <TestCache>("Test2", null); Assert.IsNull(ret); await cache.Store <TestCache>(true, "Test3", this, TimeSpan.FromMinutes(-1)); ret = await cache.Retrieve <TestCache>("Test3", null); Assert.IsNull(ret); await cache.Store <TestCache>(true, "Test4", this, TimeSpan.FromMinutes(10), AmbientClock.UtcNow.AddMinutes(11)); ret = await cache.Retrieve <TestCache>("Test4", null); Assert.AreEqual(this, ret); await cache.Store <TestCache>(true, "Test5", this, TimeSpan.FromMinutes(10), AmbientClock.Now.AddMinutes(11)); ret = await cache.Retrieve <TestCache>("Test5", null); Assert.AreEqual(this, ret); await cache.Store <TestCache>(true, "Test6", this, TimeSpan.FromMinutes(60), AmbientClock.UtcNow.AddMinutes(10)); ret = await cache.Retrieve <TestCache>("Test6", null); Assert.AreEqual(this, ret); ret = await cache.Retrieve <TestCache>("Test6", TimeSpan.FromMinutes(10)); Assert.AreEqual(this, ret); await Eject(cache, 50); await cache.Clear(); ret = await cache.Retrieve <TestCache>("Test6", null); Assert.IsNull(ret); } }
public async Task CacheAmbient() { AmbientSettingsOverride localSettingsSet = new AmbientSettingsOverride(TestCacheSettingsDictionary, nameof(CacheAmbient)); using (new ScopedLocalServiceOverride <IAmbientSettingsSet>(localSettingsSet)) { IAmbientCache localOverride = new BasicAmbientCache(); using (ScopedLocalServiceOverride <IAmbientCache> localCache = new ScopedLocalServiceOverride <IAmbientCache>(localOverride)) { TestCache ret; AmbientCache <TestCache> cache = new AmbientCache <TestCache>(); await cache.Store(true, "Test1", this); await cache.Store(true, "Test1", this); ret = await cache.Retrieve <TestCache>("Test1", null); Assert.AreEqual(this, ret); await cache.Remove <TestCache>(true, "Test1"); ret = await cache.Retrieve <TestCache>("Test1", null); Assert.IsNull(ret); await cache.Store(true, "Test2", this, null, DateTime.MinValue); ret = await cache.Retrieve <TestCache>("Test2", null); Assert.AreEqual(this, ret); await Eject(cache, 2); ret = await cache.Retrieve <TestCache>("Test2", null); Assert.IsNull(ret); await cache.Store(true, "Test3", this, TimeSpan.FromMinutes(-1)); ret = await cache.Retrieve <TestCache>("Test3", null); Assert.IsNull(ret); await cache.Store(true, "Test4", this, TimeSpan.FromMinutes(10), DateTime.UtcNow.AddMinutes(11)); ret = await cache.Retrieve <TestCache>("Test4", null); Assert.AreEqual(this, ret); await cache.Store(true, "Test5", this, TimeSpan.FromMinutes(10), DateTime.Now.AddMinutes(11)); ret = await cache.Retrieve <TestCache>("Test5", null); Assert.AreEqual(this, ret); await cache.Store(true, "Test6", this, TimeSpan.FromMinutes(60), DateTime.UtcNow.AddMinutes(10)); ret = await cache.Retrieve <TestCache>("Test6", null); Assert.AreEqual(this, ret); ret = await cache.Retrieve <TestCache>("Test6", TimeSpan.FromMinutes(10)); Assert.AreEqual(this, ret); await Eject(cache, 50); await cache.Clear(); ret = await cache.Retrieve <TestCache>("Test6", null); Assert.IsNull(ret); } } }