If factory function returns null, does GetOrSet save null in cache? #207
-
I have a situation where my factory method will return null of a record is not found. Will the GetOrSet / GetOrSetAsync store null in the cache, or does it just return null and nothing is cache? I do not want null to be cached. It wasn't clear from the docs (or I missed it). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @pbolduc and thanks for using FusionCache! FusionCache caches For example let's say that someone asks your service for Basically that is a DoS/DDoS waiting to happen. As an example, this is what StackOverflow does:
Having said that, if you think this is the good thing to do in your scenario and you really need to not cache Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
It's in the main readme, in the "Something more" details: Good catch though: probably I should put it also somewhere else to be more prominent. |
Beta Was this translation helpful? Give feedback.
Hi @pbolduc and thanks for using FusionCache!
FusionCache caches
null
like any other value, because normally not cachingnull
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, returnsnull
, butnull
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: