Skip to content
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

Question: is FastCache saving null values for a given key? #113

Open
guillaumeagile opened this issue Jul 4, 2024 · 1 comment
Open

Comments

@guillaumeagile
Copy link

or do I have to store a NullObject (using the Null Object pattern) ?

@neon-sunset
Copy link
Owner

neon-sunset commented Jul 4, 2024

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants