aboutsummaryrefslogtreecommitdiff
path: root/plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-11-02 21:35:08 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-11-02 21:35:08 -0400
commit718bed529299ea9aad03d848b835cbda1854be34 (patch)
tree5efa103be60cc512ba049bc5f9880d96faedf676 /plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs
parentd2d812213b99ee17f9433f81871b694c4053ff23 (diff)
Remove ambiguous default serializer functions
Diffstat (limited to 'plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs')
-rw-r--r--plugins/VNLib.Data.Caching.Providers.Redis/src/RedisClientCacheEntry.cs23
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));