diff options
Diffstat (limited to 'Libs/VNLib.Plugins.Essentials.Sessions.VNCache')
3 files changed, 9 insertions, 21 deletions
diff --git a/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/VNLib.Plugins.Essentials.Sessions.VNCache.csproj b/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/VNLib.Plugins.Essentials.Sessions.VNCache.csproj index 8c3e23a..dc73ed8 100644 --- a/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/VNLib.Plugins.Essentials.Sessions.VNCache.csproj +++ b/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/VNLib.Plugins.Essentials.Sessions.VNCache.csproj @@ -21,7 +21,7 @@ </ItemGroup> <ItemGroup> - <ProjectReference Include="..\..\..\..\VNLib\Http\VNLib.Net.Http.csproj" /> + <ProjectReference Include="..\..\..\..\VNLib\Http\src\VNLib.Net.Http.csproj" /> <ProjectReference Include="..\..\..\..\VNLib\Utils\src\VNLib.Utils.csproj" /> <ProjectReference Include="..\..\..\DataCaching\VNLib.Data.Caching.Extensions\VNLib.Data.Caching.Extensions.csproj" /> <ProjectReference Include="..\..\..\DataCaching\VNLib.Data.Caching\src\VNLib.Data.Caching.csproj" /> diff --git a/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProvider.cs b/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProvider.cs index 057e308..5747175 100644 --- a/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProvider.cs +++ b/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProvider.cs @@ -71,9 +71,6 @@ namespace VNLib.Plugins.Essentials.Sessions.VNCache protected override RemoteSession SessionCtor(string sessionId) => new WebSession(sessionId, Client, BackgroundUpdateTimeout, UpdateSessionId); - - private uint _waitingCount; - public async ValueTask<SessionHandle> GetSessionAsync(IHttpEvent entity, CancellationToken cancellationToken) { //Callback to close the session when the handle is closeed @@ -92,27 +89,15 @@ namespace VNLib.Plugins.Essentials.Sessions.VNCache } //Limit max number of waiting clients - if (_waitingCount > MaxConnections) + if (WaitingConnections > MaxConnections) { //Set 503 for temporary unavail entity.CloseResponse(System.Net.HttpStatusCode.ServiceUnavailable); return new SessionHandle(null, FileProcessArgs.VirtualSkip, null); } - RemoteSession session; - - //Inc waiting count - Interlocked.Increment(ref _waitingCount); - try - { - //Recover the session - session = await GetSessionAsync(entity, sessionId, cancellationToken); - } - finally - { - //Dec on exit - Interlocked.Decrement(ref _waitingCount); - } + //Get session + RemoteSession session = await GetSessionAsync(entity, sessionId, cancellationToken); //If the session is new (not in cache), then overwrite the session id with a new one as user may have specified their own if (session.IsNew) @@ -131,6 +116,7 @@ namespace VNLib.Plugins.Essentials.Sessions.VNCache session.Privilages = 0; session.SetLoginToken(null); } + return new SessionHandle(session, HandleClosedAsync); } catch (OperationCanceledException) diff --git a/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProviderEntry.cs b/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProviderEntry.cs index 382717b..8e25416 100644 --- a/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProviderEntry.cs +++ b/Libs/VNLib.Plugins.Essentials.Sessions.VNCache/WebSessionProviderEntry.cs @@ -84,7 +84,7 @@ namespace VNLib.Plugins.Essentials.Sessions.VNCache IReadOnlyDictionary<string, JsonElement> webSessionConfig) { //Init cache client - using VnCacheClient cache = new(plugin.IsDebug() ? plugin.Log : null, Memory.Shared); + using VnCacheClient cache = new(plugin.IsDebug() ? localized : null, Memory.Shared); try { @@ -97,9 +97,11 @@ namespace VNLib.Plugins.Essentials.Sessions.VNCache //Init provider _sessions = new(cache.Resource!, cacheLimit, maxConnections, idFactory); - localized.Information("Session provider loaded"); + //Listen for cache table events + _ = plugin.DeferTask(() => _sessions.CleanupExpiredSessionsAsync(localized, plugin.UnloadToken)); + //Run and wait for exit await cache.RunAsync(localized, plugin.UnloadToken); |