aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-04-08 16:44:52 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-04-08 16:44:52 -0400
commitb036e4665605e192df377290760321a8e17794e7 (patch)
treeec260b1b15d9d75fc26cecb42a105a85a377e014
parenta37e01df6b8c10525ea4311344959fe5273059c1 (diff)
Update serializer api, expose configurable buffer size
-rw-r--r--libs/VNLib.Plugins.Sessions.Cache.Client/src/GlobalCacheStore.cs7
-rw-r--r--libs/VNLib.Plugins.Sessions.Cache.Client/src/SessionDataSerialzer.cs13
-rw-r--r--libs/VNLib.Plugins.Sessions.OAuth/src/Endpoints/AccessTokenEndpoint.cs2
-rw-r--r--libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionStore.cs4
-rw-r--r--libs/VNLib.Plugins.Sessions.VNCache/src/WebSessionStore.cs4
5 files changed, 21 insertions, 9 deletions
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 <see cref="GlobalCacheStore"/> with the backing <see cref="IGlobalCacheProvider"/>
/// global cache
/// </summary>
- /// <param name="globalCache"></param>
+ /// <param name="globalCache">The backing cache store</param>
+ /// <param name="bufferSize">The size of the buffer used to serialize session objects</param>
/// <exception cref="ArgumentNullException"></exception>
- public GlobalCacheStore(IGlobalCacheProvider globalCache)
+ public GlobalCacheStore(IGlobalCacheProvider globalCache, int bufferSize)
{
_cache = globalCache ?? throw new ArgumentNullException(nameof(globalCache));
- _serialzer = new();
+ _serialzer = new(bufferSize);
}
///<inheritdoc/>
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<byte> buffer)
{
if (!type.IsAssignableTo(typeof(IDictionary<string, string>)))
@@ -59,7 +66,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client
Encoding.UTF8.GetChars(buffer, charBuffer.Span);
//Alloc new dict to write strings to
- Dictionary<string, string> output = new();
+ Dictionary<string, string> output = new(StringComparer.OrdinalIgnoreCase);
//Reader to track position of char buffer
ForwardOnlyReader<char> reader = new(charBuffer.Span[0..charCount]);
@@ -80,7 +87,7 @@ namespace VNLib.Plugins.Sessions.Cache.Client
ReadOnlySpan<char> 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<char> charBuffer = MemoryUtil.UnsafeAllocNearestPage<char>(16 * 1024);
+ using UnsafeMemoryHandle<char> charBuffer = MemoryUtil.UnsafeAllocNearestPage<char>(CharBufferSize);
using Dictionary<string, string>.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<OAuth2SessionProvider>();
- Applications = new(pbase.GetContextOptions(), pbase.GetPasswords());
+ Applications = new(pbase.GetContextOptions(), pbase.GetOrCreateSingleton<ManagedPasswordHashing>());
//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<OAuth2Session>
{
+ 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<OAuth2TokenFactory>();
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<WebSession>
{
+ 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;