Hybrid Cache - DefaultJsonSerializer Error

Heya :waving_hand:
I am a total noob with the new Hybrid Cache in .NET used in Umbraco 16.0.0 and I have some questions.

Firstly I watched Luke Hook from Gibe talk on the topic from CodeGarden to try and get me upto speed quickly and can recommend it :slight_smile:

Recommended viewing :eyes:

Error

When I bootup the site I get the following error…

[11:53:38 FTL] An error occurred starting the application
System.AggregateException: One or more errors occurred. (One or more errors occurred. ('0x92' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.))
 ---> System.AggregateException: One or more errors occurred. ('0x92' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.)
 ---> System.Text.Json.JsonException: '0x92' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
 ---> System.Text.Json.JsonReaderException: '0x92' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.JsonSerializer.GetReaderScopedToNextValue(Utf8JsonReader& reader, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
   at System.Text.Json.JsonSerializer.GetReaderScopedToNextValue(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.Read[TValue](Utf8JsonReader& reader, JsonTypeInfo`1 jsonTypeInfo)
   at Microsoft.Extensions.Caching.Hybrid.Internal.DefaultJsonSerializerFactory.DefaultJsonSerializer`1.Microsoft.Extensions.Caching.Hybrid.IHybridCacheSerializer<T>.Deserialize(ReadOnlySequence`1 source)
   at Microsoft.Extensions.Caching.Hybrid.Internal.DefaultHybridCache.MutableCacheItem`1.TryGetValue(ILogger log, T& value)
   at Microsoft.Extensions.Caching.Hybrid.Internal.DefaultHybridCache.CacheItem`1.GetReservedValue(ILogger log)
   at Microsoft.Extensions.Caching.Hybrid.Internal.DefaultHybridCache.StampedeState`2.<UnwrapReservedAsync>g__AwaitedAsync|18_0(ILogger log, Task`1 task)
   at Umbraco.Cms.Infrastructure.HybridCache.Extensions.HybridCacheExtensions.TryGetValueAsync[T](HybridCache cache, String key)
   at Umbraco.Cms.Infrastructure.HybridCache.Extensions.HybridCacheExtensions.ExistsAsync(HybridCache cache, String key)
   at Umbraco.Cms.Infrastructure.HybridCache.Services.DocumentCacheService.SeedAsync(CancellationToken cancellationToken)
   at Umbraco.Cms.Infrastructure.HybridCache.NotificationHandlers.SeedingNotificationHandler.HandleAsync(UmbracoApplicationStartedNotification notification, CancellationToken cancellationToken)
   at Umbraco.Cms.Core.Events.INotificationAsyncHandler`1.HandleAsync(IEnumerable`1 notifications, CancellationToken cancellationToken)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishCoreAsync[TNotification](IEnumerable`1 allHandlers, IEnumerable`1 notifications, CancellationToken cancellationToken)
   at Umbraco.Cms.Core.Events.NotificationAsyncHandlerWrapperImpl`1.HandleAsync[TNotification,TNotificationHandler](IEnumerable`1 notifications, CancellationToken cancellationToken, ServiceFactory serviceFactory, Func`4 publish)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishNotificationsAsync[TNotification,TNotificationHandler](IEnumerable`1 notifications, CancellationToken cancellationToken)

Project Setup

program.cs

...

// Hybrid Cache Adding in 2nd level cache (distributed cache) with Redis
// This is an example with a localhost docker instance to see/view entries
// Uses 'Microsoft.Extensions.Caching.StackExchangeRedis' nuget package
builder.Services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = builder.Configuration.GetConnectionString("RedisConnectionString");
});
...

Local Docker instance of Redis

docker run -d --name redis -p 6379:6379 redis:8.2

appsettings.json

{
    ...
	"ConnectionStrings": {
		"umbracoDbDSN": "Server=localhost;Database=someclientproject;Integrated Security=true;TrustServerCertificate=true;",
		"umbracoDbDSN_ProviderName": "Microsoft.Data.SqlClient",
		"RedisConnectionString": "127.0.0.1:6379"
	},
	"Umbraco": {
        "CMS": {
            "Cache": {
                "ContentTypeKeys": [
                    "7d8c1806-ba81-4c12-a4b3-8558a7153824" // homepage doctype
                ],
                "DocumentBreadthFirstSeedCount": 25, // default is 100
                "DocumentSeedBatchSize": 100, // default is 100
            }
            ...
        }
    }
}

Redis Insight Tool

Then I am using the Redis Insight tool to connect to the localhost instance to then try and see the entries that get put into the second level cache (as we can’t view anything stored in memory) as the 1st level cache.

When viewing it in Redis Insight tool I am getting weird symbols.
I was expecting to see the data stored against the cache item as a readable JSON format.

I have tried setting the view to JSON and MessagePack without luck.

Questions

  • Should I even be able to view the data stored against the cache key item as a nice readable JSON format or is the way I am seeing it expected behaviour ?
  • Is the FATAL error above a concern that I am going to have problems with my memory cache and distributed cache ?

Are you running 16.2? I have seen that error in earlier versions of 16 without any external cache, on cloud sites pre 16.2

Heya Matt
Yep the project is running 16.2 been upgrading it as we go from when migration started on 15

@warren Yes, I believe you should be able to see the data in the storage as you expect to see it.

I would recommend GitHub - ZiggyCreatures/FusionCache: FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features. as an option for implementing the HybridCache as it is quite a mature library - see here for MS support too FusionCache/docs/MicrosoftHybridCache.md at main · ZiggyCreatures/FusionCache · GitHub .

Hi @kieron-mcintyre
I may consider using Fusion Cache to control HybridCache a little better.

But I was originally using Redis as the distributed cache layer for HybridCache as a way to see/debug what items are going into the cache and ensuring the seed cache at bootup is working how we expect it to.

I am not working for that client until later in the week so will update this later on.

Thanks
Warren :slight_smile:

I have been able to reproduce this outside of the client project I am working on and reproduce it with Umbraco 16.2.0 and the Umbraco Clean Starter Kit from Paul Seal.

The bug report is raised here for anyone following along that also contains a video highlighting the issue

1 Like

Fixed

For anyone following along the FATAL log error message bug has been fixed in 16.3.0 with this PR

Redis Insights

I am not 100% sure if I am able to ever truly view/read the contents in Redis Insight desktop tool in a human readable way.

If anyone knows if we should or not that would be good to know :slight_smile: