aboutsummaryrefslogtreecommitdiff
path: root/Plugins/SessionProvider/GlobalCache.cs
diff options
context:
space:
mode:
authorLibravatar vman <public@vaughnnugent.com>2022-10-30 02:28:12 -0400
committerLibravatar vman <public@vaughnnugent.com>2022-10-30 02:28:12 -0400
commita8510fb835dcc5e1142d700164ce5a4bd44e1a25 (patch)
tree28caab320f777a384cb6883b68dd999cdc8c0a3f /Plugins/SessionProvider/GlobalCache.cs
Add project files.
Diffstat (limited to 'Plugins/SessionProvider/GlobalCache.cs')
-rw-r--r--Plugins/SessionProvider/GlobalCache.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/Plugins/SessionProvider/GlobalCache.cs b/Plugins/SessionProvider/GlobalCache.cs
new file mode 100644
index 0000000..ff16f47
--- /dev/null
+++ b/Plugins/SessionProvider/GlobalCache.cs
@@ -0,0 +1,141 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+//using VNLib.Data.Caching;
+//using VNLib.Net.Messaging.FBM.Client;
+//using VNLib.Net.Messaging.FBM.Client.Exceptions;
+
+
+namespace VNLib.Plugins.Essentials.Sessions
+{
+ /*internal class GlobalCache : IGlobalCacheProvider
+ {
+ private readonly FBMClient Client;
+ private readonly TimeSpan OperationTimeout;
+
+ public GlobalCache(FBMClient cacheProvider, TimeSpan cancellation)
+ {
+ this.Client = cacheProvider;
+ this.OperationTimeout = cancellation;
+ }
+
+ //If the wait handle will block, the client is connected
+ bool IGlobalCacheProvider.IsConnected => !Client.ConnectionStatusHandle.WaitOne(0);
+
+ async Task IGlobalCacheProvider.DeleteAsync(string key)
+ {
+ if (OperationTimeout > TimeSpan.Zero && OperationTimeout < TimeSpan.MaxValue)
+ {
+ CancellationTokenSource cts = new(OperationTimeout);
+ try
+ {
+ //Delete value
+ await Client.DeleteObjectAsync(key, cts.Token);
+ }
+ catch (FBMException fbm)
+ {
+ //Catch fbm excpetions and wrap them in global cache exception
+ throw new GlobalCacheException("Failed to delete cache record, see inner exception", fbm);
+ }
+ catch (OperationCanceledException)
+ {
+ throw new TimeoutException("The operation has been cancelled, due to a timeout");
+ }
+ finally
+ {
+ cts.Dispose();
+ }
+ }
+ else
+ {
+ try
+ {
+ //Delete value
+ await Client.DeleteObjectAsync(key);
+ }
+ catch (FBMException fbm)
+ {
+ //Catch fbm excpetions and wrap them in global cache exception
+ throw new GlobalCacheException("Failed to delete cache record, see inner exception", fbm);
+ }
+ }
+ }
+
+ async Task<T> IGlobalCacheProvider.GetAsync<T>(string key)
+ {
+ if (OperationTimeout > TimeSpan.Zero && OperationTimeout < TimeSpan.MaxValue)
+ {
+ CancellationTokenSource cts = new(OperationTimeout);
+ try
+ {
+ //Try to get the value
+ return await Client.GetObjectAsync<T>(key, cts.Token);
+ }
+ catch (FBMException fbm)
+ {
+ //Catch fbm excpetions and wrap them in global cache exception
+ throw new GlobalCacheException("Failed to delete cache record, see inner exception", fbm);
+ }
+ catch (OperationCanceledException)
+ {
+ throw new TimeoutException("The operation has been cancelled, due to a timeout");
+ }
+ finally
+ {
+ cts.Dispose();
+ }
+ }
+ else
+ {
+ try
+ {
+ //Try to get the value
+ return await Client.GetObjectAsync<T>(key);
+ }
+ catch (FBMException fbm)
+ {
+ //Catch fbm excpetions and wrap them in global cache exception
+ throw new GlobalCacheException("Failed to delete cache record, see inner exception", fbm);
+ }
+ }
+ }
+
+ async Task IGlobalCacheProvider.SetAsync<T>(string key, T value)
+ {
+ if (OperationTimeout > TimeSpan.Zero && OperationTimeout < TimeSpan.MaxValue)
+ {
+ CancellationTokenSource cts = new(OperationTimeout);
+ try
+ {
+ await Client.AddOrUpdateObjectAsync(key, null, value, cts.Token);
+ }
+ catch (FBMException fbm)
+ {
+ //Catch fbm excpetions and wrap them in global cache exception
+ throw new GlobalCacheException("Failed to delete cache record, see inner exception", fbm);
+ }
+ catch (OperationCanceledException)
+ {
+ throw new TimeoutException("The operation has been cancelled, due to a timeout");
+ }
+ finally
+ {
+ cts.Dispose();
+ }
+ }
+ else
+ {
+ try
+ {
+ await Client.AddOrUpdateObjectAsync(key, null, value);
+ }
+ catch (FBMException fbm)
+ {
+ //Catch fbm excpetions and wrap them in global cache exception
+ throw new GlobalCacheException("Failed to delete cache record, see inner exception", fbm);
+ }
+ }
+ }
+ }*/
+}