I actively use caching in my ASP.NET web site.
Though, some objects requested from db are really absent. For instance, I’m checking if there is a Discount for the particular product by looking record with ProductId=@ProductId in ProductsDiscount table. Absence of the record means no discount.
Do you think it is a good idea to put null discount objects into Cache?
Or I would better invent something better (using null-object pattern, for instance). In fact, I don’t really like idea to start using null-object pattern as it will require a lot of redesign that I would like to avoid at least right now.
Thanks. Any thoughts are welcome.
P.S. In fact, I can’t even put null object into Cache, when I try to call:
HttpContext.Current.Cache.Insert("name...", null);
i receive:
Value cannot be null.
P.P.S. Why MSDN tells nothing about this behavior?
For your case, you could use
DBNull.Valueas the ‘no data’ marker: