Nhibernate 和 SetCacheable 具有二级缓存

发布于 2024-10-15 22:42:32 字数 1541 浏览 8 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拍不死你 2024-10-22 22:42:32

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文