I am pretty sure that this question has been asked many times but I haven't been able to find an answer yet. DetachUserFromGroup and/or AssociateUserWith members of AuthorizationRepository don't seem to invalidate the second-level cache. I've tried to investigate more but my knowledge of Nhibernate is too poor at the moment to find a proper solution. I've downloaded Rhino-Security from here: https://github.com/ayende/rhino-security and extended AuthorizationServiceWithSecondLevelCacheFixture.
The DatabaseFixture basically creates a user, 3 groups and associate the user with all the groups: user = new User { Name = "Ayende" }; session.Save(user); authorizationService = ServiceLocator.Current.GetInstance<IAuthorizationService>(); permissionService = ServiceLocator.Current.GetInstance<IPermissionsService>(); permissionsBuilderService = ServiceLocator.Current.GetInstance<IPermissionsBuilderService>(); authorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>(); authorizationRepository.CreateUsersGroup("Administrators"); authorizationRepository.CreateUsersGroup("Users"); authorizationRepository.CreateUsersGroup("Guests"); authorizationRepository.AssociateUserWith(user, "Administrators"); authorizationRepository.AssociateUserWith(user, "Users"); authorizationRepository.AssociateUserWith(user, "Guests"); I've added this fixture [Fact] public void Test_Associated_Users_Group_For() { session.Flush(); session.Transaction.Commit(); session.Dispose(); using (var s2 = factory.OpenSession()) { using (var tx = s2.BeginTransaction()) { SillyContainer.SessionProvider = () => s2; var User = s2.CreateCriteria<User>() .Add(Restrictions.Eq("Name", "Ayende")) .UniqueResult<User>(); var anotherAuthorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>(); var Groups = anotherAuthorizationRepository.GetAssociatedUsersGroupFor(User); anotherAuthorizationRepository.DetachUserFromGroup(User, "Guests"); s2.Flush(); tx.Commit(); } } using (var s3 = factory.OpenSession()) { using (var tx = s3.BeginTransaction()) { SillyContainer.SessionProvider = () => s3; var User = s3.CreateCriteria<User>() .Add(Restrictions.Eq("Name", "Ayende")) .UniqueResult<User>(); var anotherAuthorizationRepository = ServiceLocator.Current.GetInstance<IAuthorizationRepository>(); var Groups = anotherAuthorizationRepository.GetAssociatedUsersGroupFor(User); tx.Commit(); } } } The 2nd session detaches the user from the group Guests but the 3rd session still fetches 3 groups associated with the user. It seems that the second-level cache can't be invalidated. Is there anyone who can help me? -- You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" group. To post to this group, send email to rhino-tools-dev@googlegroups.com. To unsubscribe from this group, send email to rhino-tools-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rhino-tools-dev?hl=en.