ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.87k stars 96 forks source link

[FEATURE] Disable null caching #184

Closed demorgi closed 10 months ago

demorgi commented 1 year ago

Problem

At the moment it is possible to cache null as a value for the key, sometimes it's better to run a factory each time for a null value to make sure we would receive a value as soon as it's available.

Solution

It would be great to have a configuration\strategy to make a choice to disable null caching

Alternatives

This can be achieved by building a wrapper(decorator) around the fusion cache on the consumer side but seems a little bit excessive

jodydonetti commented 1 year ago

Hi @demorgi and thanks for using FusionCache!

What you are looking for is Adaptive Caching: just before returning the value in the factory check if it is null: in that case set the Duration to TimeSpan.Zero and it will not be cached.

Hope this helps.