##591 added addanddelete method back to cache as Ocelot.Provider.Consul uses it...sigh at me (#592)

This commit is contained in:
Tom Pallister 2018-09-03 07:58:22 +01:00 committed by GitHub
parent 66b68fc685
commit 6198404697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 11 deletions

View File

@ -7,5 +7,6 @@ namespace Ocelot.Cache
void Add(string key, T value, TimeSpan ttl, string region);
T Get(string key, string region);
void ClearRegion(string region);
void AddAndDelete(string key, T value, TimeSpan ttl, string region);
}
}

View File

@ -39,6 +39,16 @@
}
}
public void AddAndDelete(string key, T value, TimeSpan ttl, string region)
{
if (_cache.ContainsKey(key))
{
_cache.Remove(key);
}
Add(key, value, ttl, region);
}
public void ClearRegion(string region)
{
if (_regions.ContainsKey(region))

View File

@ -25,6 +25,18 @@
fake.Value.ShouldBe(1);
}
[Fact]
public void should_add_and_delete()
{
var fake = new Fake(1);
_cache.Add("1", fake, TimeSpan.FromSeconds(100), "region");
var newFake = new Fake(1);
_cache.AddAndDelete("1", newFake, TimeSpan.FromSeconds(100), "region");
var result = _cache.Get("1", "region");
result.ShouldBe(newFake);
newFake.Value.ShouldBe(1);
}
[Fact]
public void should_clear_region()
{