ASP.NET不能缓存空值 [英] ASP.NET can't cache null value
本文介绍了ASP.NET不能缓存空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能解释为什么你不能插入一个空对象到ASP.NET缓存?
Can anyone explain why you cannot insert a null object into the ASP.NET cache?
string exampleItem = null;
HttpRuntime.Cache.Insert("EXAMPLE_KEY",
exampleItem,
Nothing,
DateTime.Now.AddHours(1),
System.Web.Caching.Cache.NoSlidingExpiration);
异常错误消息指出价值对象不能为空。在我的应用程序有正当的理由,为什么我们要对子级存储在缓存中的空值。
The exception error message states that the "value" object cannot be null. In my application there are valid reasons why we whould want to store a null value in the cache.
推荐答案
标的缓存
可能是一个的Hashtable
或词典<字符串对象>
,其在干将那个键,或在关键的空值没有价值之间没有区别
Underlying Cache
is likely a Hashtable
or Dictionary<string, object>
, whose getters do not differentiate between no value at that key, or a null value at that key.
Hashtable table = new Hashtable();
object x = table["foo"];
table.Add("foo", null);
object y = table["foo"];
Console.WriteLine(x == y); // prints 'True'
考虑一个占位符,使用空的项目,类似于 DbNull.Value
。
这篇关于ASP.NET不能缓存空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文