From 8fea80317bd7aa6da14eeec1c818efc9a742b855 Mon Sep 17 00:00:00 2001 From: Eduardo Arias Date: Wed, 5 Feb 2025 15:25:39 -0300 Subject: [PATCH] Use JSON source generator & enable trimming - This is based on work in PR #304 --- Src/Fido2.AspNet/DistributedCacheMetadataService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Src/Fido2.AspNet/DistributedCacheMetadataService.cs b/Src/Fido2.AspNet/DistributedCacheMetadataService.cs index fe68620d..a4a78a3c 100644 --- a/Src/Fido2.AspNet/DistributedCacheMetadataService.cs +++ b/Src/Fido2.AspNet/DistributedCacheMetadataService.cs @@ -1,5 +1,7 @@ using System.Text.Json; +using Fido2NetLib.Serialization; + using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Internal; @@ -103,7 +105,7 @@ protected virtual async Task StoreDistributedCachedBlob(IMetadataRepository repo { await _distributedCache.SetStringAsync( GetBlobCacheKey(repository), - JsonSerializer.Serialize(payload), + JsonSerializer.Serialize(payload, FidoModelSerializerContext.Default.MetadataBLOBPayload), new DistributedCacheEntryOptions() { AbsoluteExpiration = GetDistributedCacheAbsoluteExpiryTime(GetNextUpdateTimeFromPayload(payload)) @@ -120,7 +122,7 @@ protected virtual async Task GetDistributedCachedBlob(IMeta { try { - var cachedBlob = JsonSerializer.Deserialize(distributedCacheEntry); + var cachedBlob = JsonSerializer.Deserialize(distributedCacheEntry, FidoModelSerializerContext.Default.MetadataBLOBPayload); var nextUpdateTime = GetNextUpdateTimeFromPayload(cachedBlob); //If the cache until time is in the past then update and return new data, otherwise return the cached value