@Override
        public String calculateValue(QueryOptions queryOptions) {
            InheritanceGraph graph = this.user.getPlugin().getInheritanceGraphFactory().getGraph(queryOptions);

            // fully traverse the graph, obtain a list of permission holders the user inherits from in weight order.
            Iterable<PermissionHolder> traversal = graph.traverse(this.user.getPlugin().getConfiguration().get(ConfigKeys.INHERITANCE_TRAVERSAL_ALGORITHM), true, this.user);

            // return the name of the first found group
            for (PermissionHolder holder : traversal) {
                if (holder instanceof Group) {
                    return ((Group) holder).getName();
                }
            }

            // fallback to stored
            return super.calculateValue(queryOptions);
        }
Simple implementation which just holds a stored value.
common/src/main/java/me/lucko/luckperms/common/model/PrimaryGroupHolder.java