相关疑难解决方法(0)

在HttpRuntime.Cache.Add中为空值

我想为某些键存储null,HttpRuntime.Cache因为我不想再次转到数据库以找到该键没有条目.

所以第一次,它进入数据库并填充缓存.目的是使用缓存数据而不是进行数据库调用来提供以下调用.

这是我使用以下代码:

            Info info = null;
        if (HttpRuntime.Cache["Info_" + id.ToString() + "_" + quantity.ToString()] != null)
            info = HttpRuntime.Cache["Info_" + id.ToString() + "_" + quantity.ToString()] as Info;
        if (info == null)
        {
            info = (from dd in dc.Infos
                              where dd.id == id && dd.active == true && dd.quantitytooffset == quantity
                              select dd).SingleOrDefault();
            HttpRuntime.Cache.Add("Info_" + id.ToString() + "_" + quantity.ToString(), info, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null);
        }
Run Code Online (Sandbox Code Playgroud)

最后一行代码即HttpRuntime.Cache.Add抛出一个System.ArgumentNullException:Value不能为null.

任何想法是否可行或我需要使用其他数据结构来存储空值并在以后查找?

c# caching httpruntime.cache

5
推荐指数
1
解决办法
4251
查看次数

标签 统计

c# ×1

caching ×1

httpruntime.cache ×1