From b036e4665605e192df377290760321a8e17794e7 Mon Sep 17 00:00:00 2001 From: vnugent Date: Sat, 8 Apr 2023 16:44:52 -0400 Subject: Update serializer api, expose configurable buffer size --- .../src/GlobalCacheStore.cs | 7 ++++--- .../src/SessionDataSerialzer.cs | 13 ++++++++++--- .../src/Endpoints/AccessTokenEndpoint.cs | 2 +- libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionStore.cs | 4 +++- libs/VNLib.Plugins.Sessions.VNCache/src/WebSessionStore.cs | 4 +++- 5 files changed, 21 insertions(+), 9 deletions(-) (limited to 'libs') diff --git a/libs/VNLib.Plugins.Sessions.Cache.Client/src/GlobalCacheStore.cs b/libs/VNLib.Plugins.Sessions.Cache.Client/src/GlobalCacheStore.cs index bb7acd6..89b2b5b 100644 --- a/libs/VNLib.Plugins.Sessions.Cache.Client/src/GlobalCacheStore.cs +++ b/libs/VNLib.Plugins.Sessions.Cache.Client/src/GlobalCacheStore.cs @@ -45,12 +45,13 @@ namespace VNLib.Plugins.Sessions.Cache.Client /// Initiailzes a new with the backing /// global cache /// - /// + /// The backing cache store + /// The size of the buffer used to serialize session objects /// - public GlobalCacheStore(IGlobalCacheProvider globalCache) + public GlobalCacheStore(IGlobalCacheProvider globalCache, int bufferSize) { _cache = globalCache ?? throw new ArgumentNullException(nameof(globalCache)); - _serialzer = new(); + _serialzer = new(bufferSize); } /// diff --git a/libs/VNLib.Plugins.Sessions.Cache.Client/src/SessionDataSerialzer.cs b/libs/VNLib.Plugins.Sessions.Cache.Client/src/SessionDataSerialzer.cs index 3af8641..1d83f9c 100644 --- a/libs/VNLib.Plugins.Sessions.Cache.Client/src/SessionDataSerialzer.cs +++ b/libs/VNLib.Plugins.Sessions.Cache.Client/src/SessionDataSerialzer.cs @@ -42,6 +42,13 @@ namespace VNLib.Plugins.Sessions.Cache.Client { const string KV_DELIMITER = "\0\0"; + readonly int CharBufferSize; + + public SessionDataSerialzer(int charBufferSize) + { + CharBufferSize = charBufferSize; + } + object? ICacheObjectDeserialzer.Deserialze(Type type, ReadOnlySpan buffer) { if (!type.IsAssignableTo(typeof(IDictionary))) @@ -59,7 +66,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client Encoding.UTF8.GetChars(buffer, charBuffer.Span); //Alloc new dict to write strings to - Dictionary output = new(); + Dictionary output = new(StringComparer.OrdinalIgnoreCase); //Reader to track position of char buffer ForwardOnlyReader reader = new(charBuffer.Span[0..charCount]); @@ -80,7 +87,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client ReadOnlySpan key = reader.Window[0..sep]; //Advance reader to next sequence - reader.Advance(sep + 2); + reader.Advance(sep + KV_DELIMITER.Length); //Find next sepearator to recover the value sep = GetNextToken(ref reader); @@ -113,7 +120,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client } //Alloc char buffer, sessions should be under 16k - using UnsafeMemoryHandle charBuffer = MemoryUtil.UnsafeAllocNearestPage(16 * 1024); + using UnsafeMemoryHandle charBuffer = MemoryUtil.UnsafeAllocNearestPage(CharBufferSize); using Dictionary.Enumerator e = dict.GetEnumerator(); diff --git a/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs b/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs index a867152..2552d98 100644 --- a/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs +++ b/libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs @@ -70,7 +70,7 @@ namespace VNLib.Plugins.Sessions.OAuth.Endpoints //Get the session provider, as its a token factory TokenFactory = pbase.GetOrCreateSingleton(); - Applications = new(pbase.GetContextOptions(), pbase.GetPasswords()); + Applications = new(pbase.GetContextOptions(), pbase.GetOrCreateSingleton()); //Try to get the application token key for verifying signed application JWTs JWTVerificationKey = pbase.TryGetSecretAsync("application_token_key").ToJsonWebKey(); diff --git a/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionStore.cs b/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionStore.cs index 8719002..8c65bc8 100644 --- a/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionStore.cs +++ b/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionStore.cs @@ -40,6 +40,8 @@ namespace VNLib.Plugins.Sessions.OAuth [ConfigurationName(O2SessionProviderEntry.OAUTH2_CONFIG_KEY)] internal sealed class OAuth2SessionStore : SessionStore { + const int MAX_SESSION_BUFFER_SIZE = 16 * 1024; + private ILogProvider _log; protected override ISessionIdFactory IdFactory { get; } @@ -58,7 +60,7 @@ namespace VNLib.Plugins.Sessions.OAuth .GetPrefixedCache(o2Conf.CachePrefix, HashAlg.SHA256); //Create remote cache - Cache = new GlobalCacheStore(cache); + Cache = new GlobalCacheStore(cache, MAX_SESSION_BUFFER_SIZE); IdFactory = plugin.GetOrCreateSingleton(); diff --git a/libs/VNLib.Plugins.Sessions.VNCache/src/WebSessionStore.cs b/libs/VNLib.Plugins.Sessions.VNCache/src/WebSessionStore.cs index 6560f57..12644e1 100644 --- a/libs/VNLib.Plugins.Sessions.VNCache/src/WebSessionStore.cs +++ b/libs/VNLib.Plugins.Sessions.VNCache/src/WebSessionStore.cs @@ -40,6 +40,8 @@ namespace VNLib.Plugins.Sessions.VNCache [ConfigurationName(WebSessionProviderEntry.WEB_SESSION_CONFIG)] internal sealed class WebSessionStore : SessionStore { + const int MAX_SESSION_BUFFER_SIZE = 16 * 1024; + private ILogProvider? baseLog; protected override ISessionIdFactory IdFactory { get; } @@ -68,7 +70,7 @@ namespace VNLib.Plugins.Sessions.VNCache .GetPrefixedCache(cachePrefix, HashAlg.SHA256); //Create cache store from global cache - Cache = new GlobalCacheStore(cache); + Cache = new GlobalCacheStore(cache, MAX_SESSION_BUFFER_SIZE); //Default log to plugin log baseLog = pbase.Log; -- cgit