aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.VNCache
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.VNCache')
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs18
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/VnCacheClient.cs7
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
index ff73f19..0e92c22 100644
--- a/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
+++ b/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
@@ -198,8 +198,22 @@ namespace VNLib.Plugins.Extensions.VNCache
//Serialze the value
serialzer.Serialize(value, buffer);
- //Call update on raw data
- await AddOrUpdateAsync(key, newKey, buffer, cancellation);
+ DateTime currentTime = DateTime.UtcNow;
+
+ try
+ {
+ //Update remote first, and if exceptions are raised, do not update local cache
+ await Client.AddOrUpdateObjectAsync(key, newKey, (IObjectData)buffer, cancellation);
+
+ //Safe to update local cache
+ await _memCache.AddOrUpdateObjectAsync(key, newKey, static b => b.GetData(), buffer, currentTime, CancellationToken.None);
+ }
+ catch
+ {
+ //Remove local cache if exception occurs
+ await _memCache.DeleteObjectAsync(key, CancellationToken.None);
+ throw;
+ }
}
///<inheritdoc/>
diff --git a/lib/VNLib.Plugins.Extensions.VNCache/src/VnCacheClient.cs b/lib/VNLib.Plugins.Extensions.VNCache/src/VnCacheClient.cs
index 72eecd8..df7008d 100644
--- a/lib/VNLib.Plugins.Extensions.VNCache/src/VnCacheClient.cs
+++ b/lib/VNLib.Plugins.Extensions.VNCache/src/VnCacheClient.cs
@@ -189,17 +189,18 @@ namespace VNLib.Plugins.Extensions.VNCache
pluginLog.Debug("Cache server disconnected");
}
+ catch(TimeoutException)
+ {
+ pluginLog.Warn("Failed to establish a websocket connection to cache server");
+ }
catch (WebSocketException wse)
{
pluginLog.Warn("Failed to establish a websocket connection to cache server {reason}", wse.Message);
- continue;
}
//SEs may be raised when the server is not available
catch (HttpRequestException he) when (he.InnerException is SocketException)
{
pluginLog.Debug("Failed to connect to random cache server because a TCP connection could not be established");
- //Continue next loop
- continue;
}
finally
{