diff options
Diffstat (limited to 'plugins/VNLib.Data.Caching.Providers.Redis')
-rw-r--r-- | plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs b/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs index 30d936c..a0a94c9 100644 --- a/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs +++ b/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs @@ -58,8 +58,7 @@ namespace VNLib.Data.Caching.Providers.Redis public sealed class RedisClientCacheEntry : IGlobalCacheProvider { private const int InitialWriterBufferSize = 4096; - - private readonly JsonCacheObjectSerializer _fallbackSerializer; + private readonly IUnmangedHeap _defaultHeap; private readonly Task OnLoadTask; @@ -69,8 +68,9 @@ namespace VNLib.Data.Caching.Providers.Redis public RedisClientCacheEntry(PluginBase plugin, IConfigScope config) { - _fallbackSerializer = new(); _defaultHeap = MemoryUtil.Shared; + DefaultDeserializer = new JsonCacheObjectSerializer(); + DefaultSerializer = new JsonCacheObjectSerializer(); ILogProvider redisLog = plugin.Log.CreateScope("REDIS"); @@ -203,7 +203,10 @@ namespace VNLib.Data.Caching.Providers.Redis public Task InitAsync() => OnLoadTask; ///<inheritdoc/> - public Task AddOrUpdateAsync<T>(string key, string? newKey, T value, CancellationToken cancellation) => AddOrUpdateAsync(key, newKey, value, _fallbackSerializer, cancellation); + public ICacheObjectDeserializer DefaultDeserializer { get; } + + ///<inheritdoc/> + public ICacheObjectSerializer DefaultSerializer { get; } ///<inheritdoc/> public async Task AddOrUpdateAsync<T>(string key, string? newKey, T value, ICacheObjectSerializer serialzer, CancellationToken cancellation) @@ -256,13 +259,10 @@ namespace VNLib.Data.Caching.Providers.Redis ReadOnlySpan<byte> data = callback(state); length = data.Length; - //Alloc the buffer on the desired heap - MemoryManager<byte> buffer = heap.DirectAlloc<byte>(length, false); - - //Copy object data to the buffer - data.CopyTo(buffer.GetSpan()); + //Alloc the buffer on the desired heap and copy data into it + IMemoryHandle<byte> buffer = heap.AllocAndCopy(data); - return buffer; + return buffer.ToMemoryManager(true); } } @@ -274,9 +274,6 @@ namespace VNLib.Data.Caching.Providers.Redis } ///<inheritdoc/> - public Task<T?> GetAsync<T>(string key, CancellationToken cancellation) => GetAsync<T>(key, _fallbackSerializer, cancellation); - - ///<inheritdoc/> public async Task<T?> GetAsync<T>(string key, ICacheObjectDeserializer deserializer, CancellationToken cancellation) { _ = deserializer ?? throw new ArgumentNullException(nameof(deserializer)); |