Skip to content

Commit db36bac

Browse files
committed
Implement RemoveMultiAsync
1 parent 87efa8c commit db36bac

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

Enyim.Caching/IMemcachedClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public interface IMemcachedClient : IDisposable
7373

7474
bool Remove(string key);
7575
Task<bool> RemoveAsync(string key);
76+
Task<bool> RemoveMultiAsync(params string[] keys);
7677

7778
void FlushAll();
7879
Task FlushAllAsync();

Enyim.Caching/MemcachedClient.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,12 +1055,35 @@ public bool Remove(string key)
10551055
return ExecuteRemove(key).Success;
10561056
}
10571057

1058-
//TODO: Not Implement
10591058
public async Task<bool> RemoveAsync(string key)
10601059
{
10611060
return (await ExecuteRemoveAsync(key)).Success;
10621061
}
10631062

1063+
public async Task<bool> RemoveMultiAsync(params string[] keys)
1064+
{
1065+
if (keys.Length > 0)
1066+
{
1067+
var tasks = new Task<IRemoveOperationResult>[keys.Length];
1068+
1069+
for (var i = 0; i < keys.Length; i++)
1070+
{
1071+
tasks[i] = ExecuteRemoveAsync(keys[i]);
1072+
}
1073+
1074+
await Task.WhenAll(tasks);
1075+
1076+
foreach (var task in tasks)
1077+
{
1078+
if (!(await task).Success) return false;
1079+
}
1080+
1081+
return true;
1082+
}
1083+
1084+
return false;
1085+
}
1086+
10641087
/// <summary>
10651088
/// Retrieves multiple items from the cache.
10661089
/// </summary>
@@ -1416,20 +1439,20 @@ void IDistributedCache.Remove(string key)
14161439

14171440
#region [ License information ]
14181441
/* ************************************************************
1419-
*
1442+
*
14201443
* Copyright (c) 2010 Attila Kisk? enyim.com
1421-
*
1444+
*
14221445
* Licensed under the Apache License, Version 2.0 (the "License");
14231446
* you may not use this file except in compliance with the License.
14241447
* You may obtain a copy of the License at
1425-
*
1448+
*
14261449
* http://www.apache.org/licenses/LICENSE-2.0
1427-
*
1450+
*
14281451
* Unless required by applicable law or agreed to in writing, software
14291452
* distributed under the License is distributed on an "AS IS" BASIS,
14301453
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14311454
* See the License for the specific language governing permissions and
14321455
* limitations under the License.
1433-
*
1456+
*
14341457
* ************************************************************/
14351458
#endregion

Enyim.Caching/MemcachedClientT.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ public Task<bool> RemoveAsync(string key)
210210
return _memcachedClient.RemoveAsync(key);
211211
}
212212

213+
public Task<bool> RemoveMultiAsync(params string[] keys)
214+
{
215+
return _memcachedClient.RemoveMultiAsync(keys);
216+
}
217+
213218
public bool Replace(string key, object value, int cacheSeconds)
214219
{
215220
return _memcachedClient.Replace(key, value, cacheSeconds);

Enyim.Caching/NullMemcachedClient.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ public bool Remove(string key)
184184

185185
public Task<bool> RemoveAsync(string key)
186186
{
187-
return Task.FromResult<bool>(false);
187+
return Task.FromResult(false);
188+
}
189+
190+
public Task<bool> RemoveMultiAsync(params string[] keys)
191+
{
192+
return Task.FromResult(false);
188193
}
189194

190195
public ServerStats Stats()

0 commit comments

Comments
 (0)