我已经在我的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。
谢谢