fast-cache
fast-cache copied to clipboard
Question: is FastCache saving null values for a given key?
or do I have to store a NullObject (using the Null Object pattern) ?
Hi Guillaume,
There is where K : notnull constraint on keys. If you are not seeing a compiler error/warning when being passed a nullable reference type, please make sure you have <Nullable>enabled</Nullable> in your project file and optionally <WarningsAsErrors>nullable<WarningsAsErrors> for the best experience.
If you need a key value that represents None, you can wrap the key into a struct which can internally have a nullable reference/value representing that:
var key = new OptionalKey(null);
Cached<int>.Save(key, 42, TimeSpan.FromMinutes(10));
readonly record struct OptionalKey(Key? Value);