aboutsummaryrefslogtreecommitdiff
path: root/VNLib.Data.Caching
diff options
context:
space:
mode:
authorLibravatar vman <public@vaughnnugent.com>2022-12-09 13:55:05 -0500
committerLibravatar vman <public@vaughnnugent.com>2022-12-09 13:55:05 -0500
commite7c24d79f65ebec8d2605dad3d23e8eeea260843 (patch)
treedb7da6183085738c6d0c95152335ef6042f663b8 /VNLib.Data.Caching
parent8a306b5c1ccc9220f788ed055ba4859381412fbd (diff)
Negotiation + key signing updates
Diffstat (limited to 'VNLib.Data.Caching')
-rw-r--r--VNLib.Data.Caching/src/ClientExtensions.cs39
1 files changed, 17 insertions, 22 deletions
diff --git a/VNLib.Data.Caching/src/ClientExtensions.cs b/VNLib.Data.Caching/src/ClientExtensions.cs
index 1bd2174..6787d4e 100644
--- a/VNLib.Data.Caching/src/ClientExtensions.cs
+++ b/VNLib.Data.Caching/src/ClientExtensions.cs
@@ -64,13 +64,13 @@ namespace VNLib.Data.Caching
DefaultBufferSize = 128
};
-
- private static readonly ConditionalWeakTable<FBMClient, SemaphoreSlim> GetLock = new();
- private static readonly ConditionalWeakTable<FBMClient, SemaphoreSlim> UpdateLock = new();
-
- private static SemaphoreSlim GetLockCtor(FBMClient client) => new (50);
-
- private static SemaphoreSlim UpdateLockCtor(FBMClient client) => new (25);
+ private static void LogDebug(this FBMClient client, string message, params object?[] args)
+ {
+ if (client.Config.DebugLog != null)
+ {
+ client.Config.DebugLog.Debug($"[CACHE] : {message}", args);
+ }
+ }
/// <summary>
/// Gets an object from the server if it exists
@@ -87,10 +87,10 @@ namespace VNLib.Data.Caching
/// <exception cref="InvalidResponseException"></exception>
public static async Task<T?> GetObjectAsync<T>(this FBMClient client, string objectId, CancellationToken cancellationToken = default)
{
- client.Config.DebugLog?.Debug("[DEBUG] Getting object {id}", objectId);
- SemaphoreSlim getLock = GetLock.GetValue(client, GetLockCtor);
- //Wait for entry
- await getLock.WaitAsync(cancellationToken);
+ _ = client ?? throw new ArgumentNullException(nameof(client));
+
+ client.LogDebug("Getting object {id}", objectId);
+
//Rent a new request
FBMRequest request = client.RentRequest();
try
@@ -119,7 +119,6 @@ namespace VNLib.Data.Caching
}
finally
{
- getLock.Release();
client.ReturnRequest(request);
}
}
@@ -144,10 +143,10 @@ namespace VNLib.Data.Caching
/// <exception cref="ObjectNotFoundException"></exception>
public static async Task AddOrUpdateObjectAsync<T>(this FBMClient client, string objectId, string? newId, T data, CancellationToken cancellationToken = default)
{
- client.Config.DebugLog?.Debug("[DEBUG] Updating object {id}, newid {nid}", objectId, newId);
- SemaphoreSlim updateLock = UpdateLock.GetValue(client, UpdateLockCtor);
- //Wait for entry
- await updateLock.WaitAsync(cancellationToken);
+ _ = client ?? throw new ArgumentNullException(nameof(client));
+
+ client.LogDebug("Updating object {id}, newid {nid}", objectId, newId);
+
//Rent a new request
FBMRequest request = client.RentRequest();
try
@@ -189,7 +188,6 @@ namespace VNLib.Data.Caching
}
finally
{
- updateLock.Release();
//Return the request(clears data and reset)
client.ReturnRequest(request);
}
@@ -208,11 +206,9 @@ namespace VNLib.Data.Caching
/// <exception cref="ObjectNotFoundException"></exception>
public static async Task DeleteObjectAsync(this FBMClient client, string objectId, CancellationToken cancellationToken = default)
{
- client.Config.DebugLog?.Debug("[DEBUG] Deleting object {id}", objectId);
+ _ = client ?? throw new ArgumentNullException(nameof(client));
- SemaphoreSlim updateLock = UpdateLock.GetValue(client, UpdateLockCtor);
- //Wait for entry
- await updateLock.WaitAsync(cancellationToken);
+ client.LogDebug("Deleting object {id}", objectId);
//Rent a new request
FBMRequest request = client.RentRequest();
try
@@ -240,7 +236,6 @@ namespace VNLib.Data.Caching
}
finally
{
- updateLock.Release();
client.ReturnRequest(request);
}
}