aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-08-07 20:08:18 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-08-07 20:08:18 -0400
commit9c9e00515a367a7c4a916d19c3d71795f2193910 (patch)
treea1a898edbbe57c4e7ba6e2e38ac9a6c2e4b568cc /lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs
parentbd4590d7cfaf2fa554ff6c37e095975ac4eb0f02 (diff)
New api impl patch
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.VNCache/src/RemoteBackedMemoryCache.cs18
1 files changed, 16 insertions, 2 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/>