code: def _get_user_cached_perms(self):
          
          if not self.user:
              return {}, {}
          group_pks = set(self.user.groups.values_list(
              'pk',
              flat=True,
          ))
          perms = Permission.objects.filter(
              Q(user__pk=self.user.pk) | Q(group__pk__in=group_pks),
          )
          user_permissions = {}
          group_permissions = {}
          for perm in perms:
              if perm.user_id == self.user.pk:
                  user_permissions[(
                      perm.object_id,
                      perm.content_type_id,
                      perm.codename,
                      perm.approved,
                  )] = True
              # If the user has the permission do for something, but perm.user !=
              # self.user then by definition that permission came from the
              # group.
              else:
                  group_permissions[(
                      perm.object_id,
                      perm.content_type_id,
                      perm.codename,
                      perm.approved,
                  )] = True
          return user_permissions, group_permissions
docs: Set up both the user and group caches.