【问题标题】:Caching not working on production缓存不适用于生产
【发布时间】:2018-02-22 03:20:13
【问题描述】:

我使用System.Web.Caching 中的Cache 来缓存数据库中的一些数据。当我从Visual Studio 在本地机器上运行应用程序时,它工作正常。

但是当我在IIS 上运行它时,我在这一行得到Null pointer exception

cache.Insert("Postnumbers", postnumbers, dependency,
             DateTime.Now.AddDays(7), Cache.NoSlidingExpiration, 
             CacheItemPriority.Default, PostnumberRemovedCallback);

我检查了cachepostnumbersdependency,它们不为空。有谁知道什么会导致这个问题?

堆栈跟踪:

[NullReferenceException: Object reference not set to an instance of an object.]
   Solvent.Model.Persistance.General.Entities.GeneralData.LoadPostnumbers() in C:\Solvent\Solvent\Solvent.Model\Persistance\General\Entities\GeneralData.cs:39
   Solvent.Model.SolventInitializer.InitializeCache() in C:\Solvent\Solvent\Solvent.Model\Context\SolventInitializer.cs:153
   Solvent.Model.SolventInitializer.Initialize() in C:\Solvent\Solvent\Solvent.Model\Context\SolventInitializer.cs:105
   Solvent.MvcApplication.Application_Start() in C:\Solvent\Solvent\Solvent\Global.asax.cs:42

【问题讨论】:

  • 显示完整的堆栈跟踪
  • @Fildor 缓存,postnumbers 和依赖不为空,我写的。
  • @haim770 我只得到这个:[NullReferenceException: 对象引用未设置为对象的实例。] 错误消息中没有更多信息。
  • @Aleksa 啊,超读缓存...抱歉。
  • @Aleksa 在第 X 行的 BlahDiBlubbb 中没有“...”?

标签: c# .net asp.net-mvc caching


【解决方案1】:

我解决了。我用HttpRuntime.Cache.Insert() 替换了var cache = new Cahce(); cache.Insert()。 但我仍然不知道为什么第一种方式适用于本地而不是生产。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 2013-07-13
    • 1970-01-01
    • 2010-11-12
    • 2018-03-15
    • 2016-08-30
    • 2021-05-04
    • 2015-09-07
    相关资源
    最近更新 更多