public async Task Can_Replace_By_Pattern() { var model = ModelWithIdAndName.Create(1); string modelKey = "model:" + model.CreateUrn(); await cacheClient.AddAsync(modelKey, model); model = ModelWithIdAndName.Create(2); string modelKey2 = "xxmodelxx:" + model.CreateUrn(); await cacheClient.AddAsync(modelKey2, model); string s = "this is a string"; await cacheClient.AddAsync("string1", s); var removable = (IRemoveByPatternAsync)cacheClient; await removable.RemoveByPatternAsync("*model*"); ModelWithIdAndName result = await cacheClient.GetAsync <ModelWithIdAndName>(modelKey); Assert.That(result, Is.Null); result = await cacheClient.GetAsync <ModelWithIdAndName>(modelKey2); Assert.That(result, Is.Null); string result2 = await cacheClient.GetAsync <string>("string1"); Assert.That(result2, Is.EqualTo(s)); await removable.RemoveByPatternAsync("string*"); result2 = await cacheClient.GetAsync <string>("string1"); Assert.That(result2, Is.Null); }
public async Task Does_only_add_if_key_does_not_exist() { Assert.IsTrue(await cache.AddAsync("Car", "Audi")); Assert.That(await cache.GetAsync <string>("Car"), Is.EqualTo("Audi")); Assert.IsFalse(await cache.AddAsync("Car", "Ford")); Assert.That(await cache.GetAsync <string>("Car"), Is.EqualTo("Audi")); await cache.RemoveAsync("Car"); }
public async Task <bool> AddAsync <T>(string key, T value, CancellationToken token = default) { return(await cache.AddAsync(EnsurePrefix(key), value, token).ConfigAwait()); }