♻️ Refactored the cache service

This commit is contained in:
2025-12-02 22:38:47 +08:00
parent c2f72993b7
commit aca28f9318
15 changed files with 308 additions and 333 deletions

View File

@@ -0,0 +1,21 @@
using MessagePack;
namespace DysonNetwork.Shared.Cache;
public class MessagePackCacheSerializer(MessagePackSerializerOptions? options = null) : ICacheSerializer
{
private readonly MessagePackSerializerOptions _options = options ?? MessagePackSerializerOptions.Standard
.WithCompression(MessagePackCompression.Lz4BlockArray);
public string Serialize<T>(T value)
{
var bytes = MessagePackSerializer.Serialize(value!, _options);
return Convert.ToBase64String(bytes);
}
public T? Deserialize<T>(string data)
{
var bytes = Convert.FromBase64String(data);
return MessagePackSerializer.Deserialize<T>(bytes, _options);
}
}