ZiggyCreatures / FusionCache

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

[FEATURE] Disable null caching #184

Closed demorgi closed 7 months ago

demorgi commented 9 months 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 9 months 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.