aboutsummaryrefslogtreecommitdiff
path: root/Libs/VNLib.Plugins.Sessions.Cache.Client
diff options
context:
space:
mode:
Diffstat (limited to 'Libs/VNLib.Plugins.Sessions.Cache.Client')
-rw-r--r--Libs/VNLib.Plugins.Sessions.Cache.Client/GlobalCacheStore.cs64
-rw-r--r--Libs/VNLib.Plugins.Sessions.Cache.Client/IRemoteCacheStore.cs48
-rw-r--r--Libs/VNLib.Plugins.Sessions.Cache.Client/RemoteSession.cs6
-rw-r--r--Libs/VNLib.Plugins.Sessions.Cache.Client/SessionCacheClient.cs16
-rw-r--r--Libs/VNLib.Plugins.Sessions.Cache.Client/VNLib.Plugins.Sessions.Cache.Client.csproj6
5 files changed, 122 insertions, 18 deletions
diff --git a/Libs/VNLib.Plugins.Sessions.Cache.Client/GlobalCacheStore.cs b/Libs/VNLib.Plugins.Sessions.Cache.Client/GlobalCacheStore.cs
new file mode 100644
index 0000000..df3c564
--- /dev/null
+++ b/Libs/VNLib.Plugins.Sessions.Cache.Client/GlobalCacheStore.cs
@@ -0,0 +1,64 @@
+/*
+* Copyright (c) 2022 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Sessions.Cache.Client
+* File: GlobalCacheStore.cs
+*
+* GlobalCacheStore.cs is part of VNLib.Plugins.Sessions.Cache.Client which is part of the larger
+* VNLib collection of libraries and utilities.
+*
+* VNLib.Plugins.Sessions.Cache.Client is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* VNLib.Plugins.Sessions.Cache.Client is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see https://www.gnu.org/licenses/.
+*/
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+using VNLib.Data.Caching;
+
+namespace VNLib.Plugins.Sessions.Cache.Client
+{
+ /// <summary>
+ /// A wrapper class to provide a <see cref="IRemoteCacheStore"/> from
+ /// a <see cref="IGlobalCacheProvider"/> client instance
+ /// </summary>
+ public sealed class GlobalCacheStore : IRemoteCacheStore
+ {
+ private readonly IGlobalCacheProvider _cache;
+
+ public GlobalCacheStore(IGlobalCacheProvider globalCache)
+ {
+ _cache = globalCache ?? throw new ArgumentNullException(nameof(globalCache));
+ }
+
+ ///<inheritdoc/>
+ public Task AddOrUpdateObjectAsync<T>(string objectId, string? newId, T obj, CancellationToken cancellationToken = default)
+ {
+ return _cache.AddOrUpdateAsync(objectId, newId, obj, cancellationToken);
+ }
+
+ ///<inheritdoc/>
+ public Task DeleteObjectAsync(string objectId, CancellationToken cancellationToken = default)
+ {
+ return _cache.DeleteAsync(objectId, cancellationToken);
+ }
+
+ ///<inheritdoc/>
+ public Task<T?> GetObjectAsync<T>(string objectId, CancellationToken cancellationToken = default)
+ {
+ return _cache.GetAsync<T>(objectId, cancellationToken);
+ }
+ }
+}
diff --git a/Libs/VNLib.Plugins.Sessions.Cache.Client/IRemoteCacheStore.cs b/Libs/VNLib.Plugins.Sessions.Cache.Client/IRemoteCacheStore.cs
new file mode 100644
index 0000000..2a8bd49
--- /dev/null
+++ b/Libs/VNLib.Plugins.Sessions.Cache.Client/IRemoteCacheStore.cs
@@ -0,0 +1,48 @@
+/*
+* Copyright (c) 2022 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Sessions.Cache.Client
+* File: IRemoteCacheStore.cs
+*
+* IRemoteCacheStore.cs is part of VNLib.Plugins.Sessions.Cache.Client which is part of the larger
+* VNLib collection of libraries and utilities.
+*
+* VNLib.Plugins.Sessions.Cache.Client is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* VNLib.Plugins.Sessions.Cache.Client is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see https://www.gnu.org/licenses/.
+*/
+
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace VNLib.Plugins.Sessions.Cache.Client
+{
+ /// <summary>
+ /// Represents an asynchronous interface to a remote cache store
+ /// </summary>
+ public interface IRemoteCacheStore
+ {
+ /// <summary>
+ /// Gets an object from the cache provider by key
+ /// </summary>
+ /// <typeparam name="T">The data type</typeparam>
+ /// <param name="objectId">The key/id of the object to recover</param>
+ /// <param name="cancellationToken">A token to cancel the operation</param>
+ /// <returns>A task that resolves the found object or null otherwise</returns>
+ Task<T?> GetObjectAsync<T>(string objectId, CancellationToken cancellationToken = default);
+
+ Task AddOrUpdateObjectAsync<T>(string objectId, string? newId, T obj, CancellationToken cancellationToken = default);
+
+ Task DeleteObjectAsync(string objectId, CancellationToken cancellationToken = default);
+ }
+}
diff --git a/Libs/VNLib.Plugins.Sessions.Cache.Client/RemoteSession.cs b/Libs/VNLib.Plugins.Sessions.Cache.Client/RemoteSession.cs
index 3b61f68..af2c969 100644
--- a/Libs/VNLib.Plugins.Sessions.Cache.Client/RemoteSession.cs
+++ b/Libs/VNLib.Plugins.Sessions.Cache.Client/RemoteSession.cs
@@ -30,10 +30,8 @@ using System.Collections.Generic;
using Microsoft.VisualStudio.Threading;
using VNLib.Net.Http;
-using VNLib.Data.Caching;
using VNLib.Data.Caching.Exceptions;
using VNLib.Utils.Extensions;
-using VNLib.Net.Messaging.FBM.Client;
using VNLib.Plugins.Essentials.Sessions;
using VNLib.Plugins.Essentials.Extensions;
@@ -47,7 +45,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client
{
protected const string CREATED_TIME_ENTRY = "__.i.ctime";
- protected FBMClient Client { get; }
+ protected IRemoteCacheStore Client { get; }
protected TimeSpan UpdateTimeout { get; }
private readonly AsyncLazyInitializer Initializer;
@@ -57,7 +55,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client
/// </summary>
protected Dictionary<string, string>? DataStore;
- protected RemoteSession(string sessionId, FBMClient client, TimeSpan backgroundTimeOut)
+ protected RemoteSession(string sessionId, IRemoteCacheStore client, TimeSpan backgroundTimeOut)
{
SessionID = sessionId;
UpdateTimeout = backgroundTimeOut;
diff --git a/Libs/VNLib.Plugins.Sessions.Cache.Client/SessionCacheClient.cs b/Libs/VNLib.Plugins.Sessions.Cache.Client/SessionCacheClient.cs
index 2e72391..800ad66 100644
--- a/Libs/VNLib.Plugins.Sessions.Cache.Client/SessionCacheClient.cs
+++ b/Libs/VNLib.Plugins.Sessions.Cache.Client/SessionCacheClient.cs
@@ -32,7 +32,6 @@ using VNLib.Net.Http;
using VNLib.Utils.Async;
using VNLib.Utils.Logging;
using VNLib.Utils.Memory.Caching;
-using VNLib.Net.Messaging.FBM.Client;
using VNLib.Plugins.Essentials.Sessions;
namespace VNLib.Plugins.Sessions.Cache.Client
@@ -97,19 +96,19 @@ namespace VNLib.Plugins.Sessions.Cache.Client
/// <summary>
/// The client used to communicate with the cache server
/// </summary>
- protected FBMClient Client { get; }
+ protected IRemoteCacheStore Store { get; }
/// <summary>
/// Initializes a new <see cref="SessionCacheClient"/>
/// </summary>
/// <param name="client"></param>
/// <param name="maxCacheItems">The maximum number of sessions to keep in memory</param>
- protected SessionCacheClient(FBMClient client, int maxCacheItems)
+ protected SessionCacheClient(IRemoteCacheStore client, int maxCacheItems)
{
MaxLoadedEntires = maxCacheItems;
CacheLock = new();
CacheTable = new(maxCacheItems);
- Client = client;
+ Store = client;
}
private ulong _waitingCount;
@@ -202,12 +201,6 @@ namespace VNLib.Plugins.Sessions.Cache.Client
/// <returns></returns>
public async Task CleanupExpiredSessionsAsync(ILogProvider log, CancellationToken token)
{
- //Close handler
- void OnConnectionClosed(object? sender, EventArgs e) => CacheHardClear();
-
- //Attach event
- Client.ConnectionClosed += OnConnectionClosed;
-
while (true)
{
try
@@ -229,9 +222,6 @@ namespace VNLib.Plugins.Sessions.Cache.Client
log.Error(ex);
}
}
-
- //remove handler
- Client.ConnectionClosed -= OnConnectionClosed;
}
///<inheritdoc/>
diff --git a/Libs/VNLib.Plugins.Sessions.Cache.Client/VNLib.Plugins.Sessions.Cache.Client.csproj b/Libs/VNLib.Plugins.Sessions.Cache.Client/VNLib.Plugins.Sessions.Cache.Client.csproj
index a75ebe3..8271ed2 100644
--- a/Libs/VNLib.Plugins.Sessions.Cache.Client/VNLib.Plugins.Sessions.Cache.Client.csproj
+++ b/Libs/VNLib.Plugins.Sessions.Cache.Client/VNLib.Plugins.Sessions.Cache.Client.csproj
@@ -5,6 +5,8 @@
<Authors>Vaughn Nugent</Authors>
<Copyright>Copyright © 2022 Vaughn Nugent</Copyright>
<Version>1.0.1.1</Version>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>\\vaughnnugent.com\Internal\Folder Redirection\vman\Documents\Programming\Software\StrongNameingKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
@@ -38,7 +40,9 @@
<ItemGroup>
<ProjectReference Include="..\..\..\..\VNLib\Essentials\src\VNLib.Plugins.Essentials.csproj" />
- <ProjectReference Include="..\..\..\DataCaching\VNLib.Data.Caching\src\VNLib.Data.Caching.csproj" />
+ <ProjectReference Include="..\..\..\..\VNLib\Http\src\VNLib.Net.Http.csproj" />
+ <ProjectReference Include="..\..\..\..\VNLib\Utils\src\VNLib.Utils.csproj" />
+ <ProjectReference Include="..\..\..\DataCaching\VNLib.Data.Caching\VNLib.Data.Caching.csproj" />
</ItemGroup>
</Project>