Nhibernate 和 SetCacheable 具有二级缓存
我正在使用 Rhino.Security 存储库来管理我的用户/角色。
创建、删除和关联的过程工作正常,但当我使用一种方法查询时遇到问题:GetAssociatedUsersGroupFor。
第一次调用该方法时,我没有为我的用户获得任何组,因为我还没有创建任何关联。 此时,我将一个用户与几个组关联起来。
我检查数据库,可以看到关联。
现在我再次调用 GetAssociatedUsersGroupFor 但我无法获取任何组。
通过探查器,我发现这次没有涉及数据库。 我检查了代码,发现该函数使用 Nhibernate SetCacheable:
public virtual UsersGroup[] GetAssociatedUsersGroupFor(IUser user)
{
ICollection<UsersGroup> usersGroups =
SecurityCriterions.AllGroups(user)
.GetExecutableCriteria(session)
.AddOrder(Order.Asc("Name"))
.SetCacheable(true)
.List<UsersGroup>();
return usersGroups.ToArray();
}
因为我不想更改 Rhino.Security 代码,所以我想知道是否可以以任何方式覆盖或更改此行为。
更新:
我使用此指令来获取关联的组:
AuthorizationRepository.GetAssociatedUsersGroupFor(User);
我与此代码关联:
AuthorizationRepository.AssociateUserWith(User, grpName);
并分离:
AuthorizationRepository.DetachUserFromGroup(User, groupToRemove.Name);
更新
我发现我已将二级缓存留在我的配置:
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
我认为拥有二级缓存是一件好事,可以提高性能,但是,看来我完全错了。
有谁可以尝试帮助我了解这里发生的事情吗?
I am using Rhino.Security repository to manage my users/roles.
The process of creation, deletion and association works fine but I am facing a problem when I query using one method: GetAssociatedUsersGroupFor.
The first time I call the method I don't get any groups for my user cause I haven't created any association yet.
At this point I associate a user with a couple of groups.
I check in the DB and I can see the association.
Now I call again GetAssociatedUsersGroupFor but I can't get any groups.
With the profiler I've seen that the database isn't involved this time.
I've checked the code and I've found that the function uses a Nhibernate SetCacheable:
public virtual UsersGroup[] GetAssociatedUsersGroupFor(IUser user)
{
ICollection<UsersGroup> usersGroups =
SecurityCriterions.AllGroups(user)
.GetExecutableCriteria(session)
.AddOrder(Order.Asc("Name"))
.SetCacheable(true)
.List<UsersGroup>();
return usersGroups.ToArray();
}
Since I don't want to change Rhino.Security code, I would like to know if I can override or change this behaviour in any way.
UPDATE:
I use this instruction to get associated groups:
AuthorizationRepository.GetAssociatedUsersGroupFor(User);
I associate with this code:
AuthorizationRepository.AssociateUserWith(User, grpName);
and detach:
AuthorizationRepository.DetachUserFromGroup(User, groupToRemove.Name);
UPDATE
I've found out that I had left the second level cache in my config:
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
I thought it was a good thing to have a II level cache, to improve the performance but, it seems I was totally wrong.
Is there anyone who can try to help me to understand what's happening here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rhino.security 有问题.
我已经设法解决了这个问题,即使我不喜欢它。
当我更改关联时,我调用了 SessionFactory.EvictQueries() ,一切正常。
There's a problem with rhino.security.
I've managed to solve the problem, even if I don't like it.
I've called
SessionFactory.EvictQueries()
when I change an association and everything works fine.