Skip to content

Commit

Permalink
NCBC-229: Add Remove with Cas method
Browse files Browse the repository at this point in the history
  • Loading branch information
jzablocki committed Feb 19, 2013
1 parent 4388f4c commit e3c4fa2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions Enyim.Caching/IMemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface IMemcachedClient : IDisposable
CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas);

bool Remove(string key);
bool Remove(string key, ulong cas);

void FlushAll();

Expand Down
1 change: 1 addition & 0 deletions Enyim.Caching/IMemcachedResultsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface IMemcachedResultsClient
IConcatOperationResult ExecutePrepend(string key, ulong cas, ArraySegment<byte> data);

IRemoveOperationResult ExecuteRemove(string key);
IRemoveOperationResult ExecuteRemove(string key, ulong cas);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace Enyim.Caching.Memcached.Results.StatusCodes
public enum StatusCodeEnums
{
Success = 0,
NotFound
NotFound,
DataExistsForKey
}
}

Expand Down
12 changes: 11 additions & 1 deletion Enyim.Caching/MemcachedClient.Results.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,25 @@ public IConcatOperationResult ExecutePrepend(string key, ulong cas, ArraySegment
/// </summary>
/// <param name="key">The identifier for the item to delete.</param>
/// <returns>true if the item was successfully removed from the cache; false otherwise.</returns>
public IRemoveOperationResult ExecuteRemove(string key, ulong cas)
{
return PerformRemove(key, cas);
}

public IRemoveOperationResult ExecuteRemove(string key)
{
return PerformRemove(key);
}

protected IRemoveOperationResult PerformRemove(string key, ulong cas = 0)
{
var hashedKey = this.keyTransformer.Transform(key);
var node = this.pool.Locate(hashedKey);
var result = RemoveOperationResultFactory.Create();

if (node != null)
{
var command = this.pool.OperationFactory.Delete(hashedKey, 0);
var command = this.pool.OperationFactory.Delete(hashedKey, cas);
var commandResult = node.Execute(command);

if (commandResult.Success)
Expand Down
11 changes: 11 additions & 0 deletions Enyim.Caching/MemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,17 @@ public bool Remove(string key)
return ExecuteRemove(key).Success;
}

/// <summary>
/// Removes the specified item from the cache.
/// </summary>
/// <param name="key">The identifier for the item to delete.</param>
/// <param name="cas">The Cas value associated with the key</param>
/// <returns>true if the item was successfully removed from the cache; false otherwise.</returns>
public bool Remove(string key, ulong cas)
{
return ExecuteRemove(key, cas).Success;
}

/// <summary>
/// Retrieves multiple items from the cache.
/// </summary>
Expand Down

0 comments on commit e3c4fa2

Please sign in to comment.