简体   繁体   English

NHIbernate SysCache2和SQLDependency问题

[英]NHIbernate SysCache2 and SQLDependency problems

I've set enable_broker on my SQL Server 2008 to use SQLDepndency 我在SQL Server 2008上设置了enable_broker以使用SQLDepndency

I've configured my .Net app to use Syscache2 with a cache region as follows: 我已经将我的.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>

My Hbm file looks like this: 我的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>

I also have query caching enabled for queries against BlogEntry 我还为BlogEntry的查询启用了查询缓存

When I first query, the results are cached in the 2nd level cache, as expected. 当我第一次查询时,结果将缓存在二级缓存中,如预期的那样。

If I now go and change a row in blog_entries, everything works as expected, the cache is expired, it get's this message: 如果我现在去更改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

I expect that. 我希望如此。 On the next page request, the query and it's results are stored back in the cache. 在下一页请求中,查询及其结果将存储回缓存中。 However, the cache is immediately invalidated again, even though nothing has further changed. 但是,即使没有进一步更改,缓存也会立即再次失效。

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

My cache is constantly invalidated every subsequent time with no changes to the underlying data. 我的缓存每次都会不断失效,而不会对基础数据进行任何更改。 Only a restart of the application allows the cache to operate again - but only the first time the data is cached (again, the first dirtying of the cache, causes it to never work again) 只有重新启动应用程序才允许缓存再次运行 - 但只是第一次缓存数据(再次,缓存的第一次弄脏,导致它再也不会工作)

Has anyone seen this problem or got any ideas what this could be? 有没有人看到这个问题或有任何想法这可能是什么? I was thinking that syscache2 needs to handle the SQLDependency onChange event, which it probably is doing - so I don't understand why SQL Server keeps sending SQLDependency depedencyChanged. 我以为syscache2需要处理它可能正在执行的SQLDependency onChange事件 - 所以我不明白为什么SQL Server不断发送SQLDependency depedencyChanged。

thanks 谢谢

We are getting the same problem on one database instance, but not on the other. 我们在一个数据库实例上遇到了同样的问题,但在另一个数据库实例上没有。 It definitely seems to be some kind of permission problem on the database end, because the exact same NHibernate configuration is used in both cases. 它似乎肯定是数据库端的某种权限问题,因为在两种情况下都使用完全相同的NHibernate配置。

In the working case the cache behaves as expected, in the other (which is a database engine which has much stricter permissions) we get the exact same behaviour you mentioned. 在工作的情况下,缓存的行为与预期的一样,在另一个(这是一个具有更严格权限的数据库引擎)中,我们得到了您提到的完全相同的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM