mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
##591 added addanddelete method back to cache as Ocelot.Provider.Consul uses it...sigh at me (#592)
This commit is contained in:
parent
66b68fc685
commit
6198404697
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user