def test_get_user_and_profile_through_cache(self): UserService.invalidate_user_cache(user_id=self.user1.id) UserService.invalidate_user_cache(user_id=self.user2.id) user1 = UserService.get_user_through_cache(self.user1.id) profile1 = UserService.get_profile_through_cache(self.user1.id) self.assertEqual(user1.id, profile1.user_id) UserService.invalidate_profile_cache(self.user1.id) profile1 = UserService.get_profile_through_cache(self.user1.id)
def profile_changed(sender, instance, **kwargs): # import 写在函数里面避免循环依赖 from accounts.services import UserService UserService.invalidate_profile_cache(instance.user_id)
def invalidate_profile_cache(instance, **kwargs): from accounts.services import UserService UserService.invalidate_profile_cache(instance.user_id)