Skip to content

Commit

Permalink
Make key-value input parameter to all MultiStoreAsync methods IDictio…
Browse files Browse the repository at this point in the history
…nary instead of concrete dictionary.
  • Loading branch information
TonySkorik committed Jun 27, 2024
1 parent 1afbe14 commit 2aa5157
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 71 deletions.
135 changes: 69 additions & 66 deletions src/Aer.Memcached.Client/Interfaces/IMemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace Aer.Memcached.Client.Interfaces;
public interface IMemcachedClient
{
/// <summary>
/// Stores value by key
/// Stores value by key.
/// </summary>
/// <param name="key">Key</param>
/// <param name="value">Value</param>
/// <param name="expirationTime">Expiration time</param>
/// <param name="token">Cancellation token</param>
/// <param name="storeMode">Store mode</param>
/// <param name="cacheSyncOptions">The options that configure cache sync</param>
/// <returns>Result that shows if operation was successful or not</returns>
/// <param name="key">Key.</param>
/// <param name="value">Value.</param>
/// <param name="expirationTime">Expiration time.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="storeMode">Store mode.</param>
/// <param name="cacheSyncOptions">The options that configure cache sync.</param>
/// <returns>Result that shows if operation was successful or not.</returns>
Task<MemcachedClientResult> StoreAsync<T>(
string key,
T value,
Expand All @@ -27,17 +27,17 @@ Task<MemcachedClientResult> StoreAsync<T>(
CacheSyncOptions cacheSyncOptions = null);

/// <summary>
/// Stores multiple values
/// Stores multiple values.
/// </summary>
/// <param name="keyValues">Values by keys</param>
/// <param name="expirationTime">Expiration time</param>
/// <param name="token">Cancellation token</param>
/// <param name="storeMode">Store mode</param>
/// <param name="batchingOptions">The options that configure internal key-values batching</param>
/// <param name="cacheSyncOptions">The options that configure cache sync</param>
/// <param name="replicationFactor">Number of physical nodes replication of data</param>
/// <param name="keyValues">Values by keys.</param>
/// <param name="expirationTime">Expiration time.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="storeMode">Store mode.</param>
/// <param name="batchingOptions">The options that configure internal key-values batching.</param>
/// <param name="cacheSyncOptions">The options that configure cache sync.</param>
/// <param name="replicationFactor">Number of physical nodes replication of data.</param>
Task<MemcachedClientResult> MultiStoreAsync<T>(
Dictionary<string, T> keyValues,
IDictionary<string, T> keyValues,
TimeSpan? expirationTime,
CancellationToken token,
StoreMode storeMode = StoreMode.Set,
Expand All @@ -46,17 +46,17 @@ Task<MemcachedClientResult> MultiStoreAsync<T>(
uint replicationFactor = 0);

/// <summary>
/// Stores multiple values
/// Stores multiple values.
/// </summary>
/// <param name="keyValues">Values by keys</param>
/// <param name="expirationTime">Expiration time</param>
/// <param name="token">Cancellation token</param>
/// <param name="storeMode">Store mode</param>
/// <param name="batchingOptions">The options that configure internal key-values batching</param>
/// <param name="cacheSyncOptions">The options that configure cache sync</param>
/// <param name="replicationFactor">Number of physical nodes replication of data</param>
/// <param name="keyValues">Values by keys.</param>
/// <param name="expirationTime">Expiration time.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="storeMode">Store mode.</param>
/// <param name="batchingOptions">The options that configure internal key-values batching.</param>
/// <param name="cacheSyncOptions">The options that configure cache sync.</param>
/// <param name="replicationFactor">Number of physical nodes replication of data.</param>
Task<MemcachedClientResult> MultiStoreAsync<T>(
Dictionary<string, T> keyValues,
IDictionary<string, T> keyValues,
DateTimeOffset? expirationTime,
CancellationToken token,
StoreMode storeMode = StoreMode.Set,
Expand All @@ -65,21 +65,24 @@ Task<MemcachedClientResult> MultiStoreAsync<T>(
uint replicationFactor = 0);

/// <summary>
/// Gets one value by key
/// Gets one value by key.
/// </summary>
/// <param name="key">Key</param>
/// <param name="token">Cancellation token</param>
/// <returns>Value by key and if operation was successful or not. If operation was unsuccessful default value is returned</returns>
/// <param name="key">Key.</param>
/// <param name="token">Cancellation token.</param>
/// <returns>
/// Value by key and if operation was successful or not.
/// If operation was unsuccessful default value is returned.
/// </returns>
Task<MemcachedClientValueResult<T>> GetAsync<T>(string key, CancellationToken token);

/// <summary>
/// Gets multiple values by keys
/// Gets multiple values by keys.
/// </summary>
/// <param name="keys">Keys</param>
/// <param name="token">Cancellation token</param>
/// <param name="batchingOptions">The options that configure internal keys batching</param>
/// <param name="replicationFactor">Number of physical nodes which will be requested to obtain data</param>
/// <returns>Values by keys. Only found in memcached keys are returned</returns>
/// <param name="keys">Keys.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="batchingOptions">The options that configure internal keys batching.</param>
/// <param name="replicationFactor">Number of physical nodes which will be requested to obtain data.</param>
/// <returns>Values by keys. Only found in memcached keys are returned.</returns>
Task<IDictionary<string, T>> MultiGetAsync<T>(IEnumerable<string> keys,
CancellationToken token,
BatchingOptions batchingOptions = null,
Expand All @@ -88,36 +91,36 @@ Task<IDictionary<string, T>> MultiGetAsync<T>(IEnumerable<string> keys,
/// <summary>
/// Gets multiple values by keys. Does not throw exceptions and returns a not-null value.
/// </summary>
/// <param name="keys">Keys</param>
/// <param name="token">Cancellation token</param>
/// <param name="batchingOptions">The options that configure internal keys batching</param>
/// <param name="replicationFactor">Number of physical nodes which will be requested to obtain data</param>
/// <returns>Values by keys. Only found in memcached keys are returned</returns>
/// <param name="keys">Keys.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="batchingOptions">The options that configure internal keys batching.</param>
/// <param name="replicationFactor">Number of physical nodes which will be requested to obtain data.</param>
/// <returns>Values by keys. Only found in memcached keys are returned.</returns>
Task<MemcachedClientValueResult<IDictionary<string, T>>> MultiGetSafeAsync<T>(
IEnumerable<string> keys,
CancellationToken token,
BatchingOptions batchingOptions = null,
uint replicationFactor = 0);

/// <summary>
/// Deletes one value by key
/// Deletes one value by key.
/// </summary>
/// <param name="key">Key</param>
/// <param name="token">Cancellation token</param>
/// <param name="cacheSyncOptions">The options that configure cache sync</param>
/// <param name="key">Key.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="cacheSyncOptions">The options that configure cache sync.</param>
Task<MemcachedClientResult> DeleteAsync(
string key,
CancellationToken token,
CacheSyncOptions cacheSyncOptions = null);

/// <summary>
/// Deletes multiple values by keys
/// Deletes multiple values by keys.
/// </summary>
/// <param name="keys">Keys</param>
/// <param name="token">Cancellation token</param>
/// <param name="batchingOptions">The options that configure internal keys batching</param>
/// <param name="cacheSyncOptions">The options that configure cache sync</param>
/// <param name="replicationFactor">Number of physical nodes to try delete keys</param>
/// <param name="keys">Keys.</param>
/// <param name="token">Cancellation token.</param>
/// <param name="batchingOptions">The options that configure internal keys batching.</param>
/// <param name="cacheSyncOptions">The options that configure cache sync.</param>
/// <param name="replicationFactor">Number of physical nodes to try to delete keys on.</param>
Task<MemcachedClientResult> MultiDeleteAsync(
IEnumerable<string> keys,
CancellationToken token,
Expand All @@ -126,14 +129,14 @@ Task<MemcachedClientResult> MultiDeleteAsync(
uint replicationFactor = 0);

/// <summary>
/// Increments value by key
/// Increments value by key.
/// </summary>
/// <param name="key">Key</param>
/// <param name="amountToAdd">Amount to add</param>
/// <param name="initialValue">Initial value if key doesn't exist</param>
/// <param name="expirationTime">Expiration time</param>
/// <param name="token">Cancellation token</param>
/// <returns>Incremented value</returns>
/// <param name="key">Key.</param>
/// <param name="amountToAdd">Amount to add.</param>
/// <param name="initialValue">Initial value if key doesn't exist.</param>
/// <param name="expirationTime">Expiration time.</param>
/// <param name="token">Cancellation token.</param>
/// <returns>Incremented value.</returns>
Task<MemcachedClientValueResult<ulong>> IncrAsync(
string key,
ulong amountToAdd,
Expand All @@ -142,14 +145,14 @@ Task<MemcachedClientValueResult<ulong>> IncrAsync(
CancellationToken token);

/// <summary>
/// Increments value by key
/// Increments value by key.
/// </summary>
/// <param name="key">Key</param>
/// <param name="amountToSubtract">Amount to subtract</param>
/// <param name="initialValue">Initial value if key doesn't exist</param>
/// <param name="expirationTime">Expiration time</param>
/// <param name="token">Cancellation token</param>
/// <returns>Decremented value</returns>
/// <param name="key">Key.</param>
/// <param name="amountToSubtract">Amount to subtract.</param>
/// <param name="initialValue">Initial value if key doesn't exist.</param>
/// <param name="expirationTime">Expiration time.</param>
/// <param name="token">Cancellation token.</param>
/// <returns>Decremented value.</returns>
Task<MemcachedClientValueResult<ulong>> DecrAsync(
string key,
ulong amountToSubtract,
Expand All @@ -158,7 +161,7 @@ Task<MemcachedClientValueResult<ulong>> DecrAsync(
CancellationToken token);

/// <summary>
/// Flush memcached data
/// Delete all key-value items.
/// </summary>
Task<MemcachedClientResult> FlushAsync(CancellationToken token);

Expand Down
8 changes: 4 additions & 4 deletions src/Aer.Memcached.Client/MemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task<MemcachedClientResult> StoreAsync<T>(

/// <inheritdoc />
public async Task<MemcachedClientResult> MultiStoreAsync<T>(
Dictionary<string, T> keyValues,
IDictionary<string, T> keyValues,
TimeSpan? expirationTime,
CancellationToken token,
StoreMode storeMode = StoreMode.Set,
Expand Down Expand Up @@ -172,7 +172,7 @@ public async Task<MemcachedClientResult> MultiStoreAsync<T>(

/// <inheritdoc />
public async Task<MemcachedClientResult> MultiStoreAsync<T>(
Dictionary<string, T> keyValues,
IDictionary<string, T> keyValues,
DateTimeOffset? expirationTime,
CancellationToken token,
StoreMode storeMode = StoreMode.Set,
Expand Down Expand Up @@ -602,7 +602,7 @@ public async Task<MemcachedClientResult> FlushAsync(CancellationToken token)
private async Task MultiStoreInternalAsync<T>(
IDictionary<ReplicatedNode<TNode>, ConcurrentBag<string>> nodes,
Dictionary<string, uint> keyToExpirationMap,
Dictionary<string, T> keyValues,
IDictionary<string, T> keyValues,
CancellationToken token,
StoreMode storeMode = StoreMode.Set,
BatchingOptions batchingOptions = null)
Expand Down Expand Up @@ -664,7 +664,7 @@ public bool IsCacheSyncEnabled() => _cacheSynchronizer != null

private async Task MultiStoreBatchedInternalAsync<T>(
IDictionary<ReplicatedNode<TNode>, ConcurrentBag<string>> nodes,
Dictionary<string, T> keyValues,
IDictionary<string, T> keyValues,
BatchingOptions batchingOptions,
Dictionary<string, uint> keyToExpirationMap,
StoreMode storeMode,
Expand Down
12 changes: 11 additions & 1 deletion src/Aer.Memcached.Client/Models/CacheSyncModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
namespace Aer.Memcached.Client.Models;

/// <summary>
/// Represents a multi-cluster cache synchronization key-value DTO.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
public class CacheSyncModel<T>
{
public Dictionary<string, T> KeyValues { get; set; }
/// <summary>
/// Gets or sets the key-values to sync.
/// </summary>
public IDictionary<string, T> KeyValues { get; set; }

/// <summary>
/// Gets or sets the key-value items expiration time.
/// </summary>
public DateTimeOffset? ExpirationTime { get; set; }
}

0 comments on commit 2aa5157

Please sign in to comment.