Skip to content

If factory function returns null, does GetOrSet save null in cache? #207

Answered by jodydonetti
pbolduc asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @pbolduc and thanks for using FusionCache!

FusionCache caches null like any other value, because normally not caching null will lead to problems.

For example let's say that someone asks your service for /product/123 and that product doesn't exist: the factory goes to the database, returns null, but null is not cached. This means that evey single request for it will go to the database, again and again.

Basically that is a DoS/DDoS waiting to happen.

As an example, this is what StackOverflow does:

It also allows the caching of a null value and makes that handling not special-cased. In other words, you can tell the difference between “It’s not cached” and “We looked it up. It was null. W…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by pbolduc
Comment options

You must be logged in to vote
4 replies
@pbolduc
Comment options

@jodydonetti
Comment options

@pbolduc
Comment options

@jodydonetti
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants