【问题标题】:NHIbernate SysCache2 and SQLDependency problemsNHIbernate SysCache2 和 SQLDependency 问题
【发布时间】:2011-01-23 10:11:55
【问题描述】:

我已在我的 SQL Server 2008 上设置 enable_broker 以使用 SQLDepndency

我已将 .Net 应用程序配置为使用带有缓存区域的 Syscache2,如下所示:

  <syscache2>
      <cacheRegion name="BlogEntriesCacheRegion" priority="High">
        <dependencies>
          <commands>
            <add name="BlogEntries" 
                 command="Select EntryId from dbo.Blog_Entries where ENABLED=1" 
            />
          </commands>
        </dependencies>
      </cacheRegion>
  </syscache2>

我的 Hbm 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  <class name="BlogEntry" table="Blog_Entries">

    <cache usage="nonstrict-read-write" region="BlogEntriesCacheRegion"/>
    ....
  </class>
</hibernate-mapping>

我还为针对 BlogEntry 的查询启用了查询缓存

当我第一次查询时,结果按预期缓存在二级缓存中。

如果我现在去更改 blog_entries 中的一行,一切都会按预期进行,缓存已过期,它会收到以下消息:

2010-03-03 12:56:50,583 [7] DEBUG NHibernate.Caches.SysCache2.SysCacheRegion - Cache items for region 'BlogEntriesCacheRegion' have been removed from the cache for the following reason : DependencyChanged

我希望如此。在下一页请求中,查询及其结果将存储回缓存中。但是,即使没有进一步更改,缓存也会立即再次失效。

DEBUG NHibernate.Caches.SysCache2.SysCacheRegion - Cache items for region 'BlogEntriesCacheRegion' have been removed from the cache for the following reason : DependencyChanged

我的缓存每次后续都会不断失效,而基础数据没有任何更改。只有重新启动应用程序才能让缓存再次运行 - 但只有第一次缓存数据时(同样,缓存的第一次变脏,导致它不再工作)

有没有人看到这个问题或知道这可能是什么?我在想 syscache2 需要处理它可能正在执行的 SQLDependency onChange 事件 - 所以我不明白为什么 SQL Server 不断发送 SQLDependency depedencyChanged。

谢谢

【问题讨论】:

  • 你能检查一下 SQL Profiler 发生了什么吗? SQLDependency 需要一些奇怪的权限,也许与此有关?

标签: sql-server-2005 nhibernate caching sqldependency syscache2


【解决方案1】:

我们在一个数据库实例上遇到了同样的问题,但在另一个数据库实例上却没有。这肯定似乎是数据库端的某种权限问题,因为在两种情况下都使用了完全相同的 NHibernate 配置。

在工作情况下,缓存的行为符合预期,在另一种情况下(这是一个具有更严格权限的数据库引擎),我们得到的行为与您提到的完全相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多