-
Notifications
You must be signed in to change notification settings - Fork 792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HybridCache support for Tuples #5716
Comments
Actually, The problem is DefaultHybridCache serializes/deserializes the cache item using System.Text.Json.Serializer with var valueTuple = ValueTuple.Create<int, string>(123, "string");
var tuple = Tuple.Create<int, string>(123, "string");
var optionsIncludeFields = new JsonSerializerOptions()
{
IncludeFields = true
};
string tupleJsonString = JsonSerializer.Serialize(tuple, JsonSerializerOptions.Default);
string valueTupleJsonString = JsonSerializer.Serialize(valueTuple, JsonSerializerOptions.Default);
string valueTupleJsonStringIncludeFields = JsonSerializer.Serialize(valueTuple, optionsIncludeFields);
Console.WriteLine("Vuple serialized with default:\t{0}", tupleJsonString);
Console.WriteLine("ValueTuple serialized with default:\t{0}", valueTupleJsonString);
Console.WriteLine("ValueTuple serialized with fields: \t{0}", valueTupleJsonStringIncludeFields);
//Output
//Tuple serialized with default: {"Item1":123,"Item2":"string"}
//ValueTuple serialized with default: {}
//ValueTuple serialized with fields: {"Item1":123,"Item2":"string"} |
In addition to #5827, I propose that we detect value-tuples and use a shared field-enabled options instance; we can't do that globally without changing behaviour, but I think it is the correct choice for value-tuples. |
- support value-tuples (requires field mode) - support global custom JSON options via keyed DI fix dotnet#5716 fix dotnet#5827
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I've been trying to implement a system based on eTag to return a 304 in case the existing resource has not changed in the Database.
I have a HybridCache instance working alongside this ETag in the API layer. When returning a tuple ( obj, string ) from the cache, they are returned as null, even if values are attributed in the service call. Provided sample code:
Describe the solution you'd like
I expect the tuple to retain it's value after the Func has finished it's execution.
Additional context
The text was updated successfully, but these errors were encountered: