@@ -54,6 +54,11 @@ public class UserGroupService : IUserGroupService
5454 /// </summary>
5555 private IUserGroupAttributeRepository userGroupAttributeRepository ;
5656
57+ /// <summary>
58+ /// The caching service.
59+ /// </summary>
60+ private readonly ICachingService cachingService ;
61+
5762 /// <summary>
5863 /// Initializes a new instance of the <see cref="UserGroupService"/> class.
5964 /// </summary>
@@ -64,14 +69,16 @@ public class UserGroupService : IUserGroupService
6469 /// <param name="scopeRepository">The scope repository.</param>
6570 /// <param name="userGroupAttributeRepository">The user group attribute repository.</param>
6671 /// <param name="mapper">The mapper.</param>
72+ /// <param name="cachingService">The caching service.</param>
6773 public UserGroupService (
6874 ICatalogueService catalogueService ,
6975 IUserGroupRepository userGroupRepository ,
7076 IUserUserGroupRepository userUserGroupRepository ,
7177 IScopeRepository scopeRepository ,
7278 IRoleUserGroupRepository roleUserGroupRepository ,
7379 IUserGroupAttributeRepository userGroupAttributeRepository ,
74- IMapper mapper )
80+ IMapper mapper ,
81+ ICachingService cachingService )
7582 {
7683 this . catalogueService = catalogueService ;
7784 this . userGroupRepository = userGroupRepository ;
@@ -80,6 +87,7 @@ public UserGroupService(
8087 this . roleUserGroupRepository = roleUserGroupRepository ;
8188 this . userGroupAttributeRepository = userGroupAttributeRepository ;
8289 this . mapper = mapper ;
90+ this . cachingService = cachingService ;
8391 }
8492
8593 /// <summary>
@@ -106,7 +114,21 @@ public async Task<UserGroup> GetByIdAsync(int id, bool includeRoles)
106114 /// <inheritdoc />
107115 public async Task < bool > UserHasCatalogueContributionPermission ( int userId )
108116 {
109- var userRoleGroups = await this . roleUserGroupRepository . GetRoleUserGroupViewModelsByUserId ( userId ) ;
117+
118+ string cacheKey = $ "{ userId } :AllRolesWithPermissions";
119+ var userRoleGroupsInCache = await this . cachingService . GetAsync < List < RoleUserGroupViewModel > > ( cacheKey ) ;
120+ var userRoleGroups = new List < RoleUserGroupViewModel > ( ) ;
121+
122+ if ( userRoleGroupsInCache . ResponseEnum == CacheReadResponseEnum . Found )
123+ {
124+ userRoleGroups = userRoleGroupsInCache . Item ;
125+ }
126+ else
127+ {
128+ userRoleGroups = await this . roleUserGroupRepository . GetRoleUserGroupViewModelsByUserId ( userId ) ;
129+ await this . cachingService . SetAsync ( $ "{ userId } :AllRolesWithPermissions", userRoleGroups ) ;
130+ }
131+
110132 if ( userRoleGroups != null && userRoleGroups . Any ( r => r . RoleEnum == RoleEnum . Editor ) )
111133 {
112134 return true ;
0 commit comments