2
是否正确执行我的缓存对象像这样在我的控制器:在控制器实现的System.Web.Caching.Cache对象缓存特定查询
public class HomeController : BaseController
{
public static Cache cachingControl = new Cache();
...
我用它是这样的:
public ActionResult Home()
{
IndexViewData view = new IndexViewData();
view.UserId = UserId;
if (cachingControl.Get("viewHome") != null) {
view = (IndexViewData)cachingControl.Get("viewHome");
} else {
view.allAdsList = AllAds(5000, 0);
if (Request.QueryString["voirTous"] != null)
view.loadGeneral(true);
else
view.loadGeneral(false);
cachingControl.Insert("viewHome", view);
}
view.adsList = SetupSearch(5, false, 0);
return View(view);
}
但是当我把这个行:
if (cachingControl.Get("viewHome") != null) {
他们特罗我的错误
NullErrorException
但我知道它可以为null这就是为什么我把这个条件
你有一个替代或者给我一个提示,谢谢你!
PS:我知道这些代码是怪异:P,但我一定要支持......