I'm using EasyCaching on an ASP.NET MVC app for handling Redis. As stated in the documentation (Precautions), using the MessagePack serializer will cause problems with the time zone data. There is a solution stated there and I'm using it but it's still not working as intended.
This is my current EasyCaching setup:
builder.Services.AddEasyCaching(options =>
{
options.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
config.SerializerName = "mymsgpack";
}, "redis1");
options.WithMessagePack(x =>
{
x.EnableCustomResolver = true;
x.CustomResolvers = CompositeResolver.Create(new MessagePack.IFormatterResolver[]
{
NativeDateTimeResolver.Instance,
ContractlessStandardResolver.Instance
});
}, "mymsgpack");
});
It's mostly the default configurations. I've implemented a monitoring tool that somewhat works like logging some data. You tell it to add a metric and then it shows all the metrics in a web page. The function call to add a metric (or "log" a metric) looks like this:
_metric.AddItem("IAM", DateTime.Now, MetricAggregation.Date);
This means that "I want to log the current date-time in the metric called 'IAM', and this metric has an aggregation type of date". The last part is not important (regarding the current problem). When I'm viewing the web page, all the date time data are displayed in GMT (And not GMT+3:30 which is my current time zone).
Before using EasyCaching, I used an in-memory solution and stored all the data in a dictionary. That worked as intended but I wanted to store the data for when the server goes down or fails for any reason.
I'm not insisting on using MessagePack for serialization, it was what EasyCaching used as default in their setup guide. But any help is appreciated, thanks.
So I ended up changing the serialization method, since I couldn't do anything else with MessagePack. Using json, the problem is solved:
services.AddEasyCaching(options =>
{
options.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
config.SerializerName = "myjson";
}, "redis1");
options.WithJson("myjson");
});
(I've changed the location of this configuration, hence the removal of builder
at the start of the code)