Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Enyim.Caching/IMemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public interface IMemcachedClient : IDisposable
Task<bool> RemoveAsync(string key);

void FlushAll();
Task FlushAllAsync();

ServerStats Stats();
ServerStats Stats(string type);
Expand Down
14 changes: 14 additions & 0 deletions Enyim.Caching/MemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,20 @@ public void FlushAll()
}
}

public async Task FlushAllAsync()
{
var tasks = new List<Task>();

foreach (var node in this.pool.GetWorkingNodes())
{
var command = this.pool.OperationFactory.Flush();

tasks.Add(node.ExecuteAsync(command));
}

await Task.WhenAll(tasks);
}

/// <summary>
/// Returns statistics about the servers.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Enyim.Caching/NullMemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,10 @@ public Task<T> GetValueOrCreateAsync<T>(string key, int cacheSeconds, Task<T> ge
{
return generator;
}

public Task FlushAllAsync()
{
return Task.CompletedTask;
}
}
}
21 changes: 21 additions & 0 deletions MemcachedTest/MemcachedClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,27 @@ public void IncrementLongTest()
Assert.Equal(initialValue + 24, client.Increment("VALUE", 10UL, 24UL));
}
}

[Fact]
public async Task FlushTest()
{
using (MemcachedClient client = GetClient())
{
for (int i = 0; i < 10; i++)
{
string cacheKey = $"Hello_Flush_{i}";
Assert.True(await client.StoreAsync(StoreMode.Set, cacheKey, i, DateTime.Now.AddSeconds(30)));
}

await client.FlushAllAsync();

for (int i = 0; i < 10; i++)
{
string cacheKey = $"Hello_Flush_{i}";
Assert.Null(await client.GetValueAsync<string>(cacheKey));
}
}
}
}
}

Expand Down