Melt the butter in a large saucepan over medium-high heat until it foams. Add the onions and reduce the heat to medium-low. Cook, stirring occasionally, for an hour. The onions should be translucent and almost jammy.Preheat the oven to 400°F. Grease two 12-cup muffin tins with butter.Carefully transfer the onions to the bowl of a large food processor. Add the cream, sour cream, salt, pepper, nutmeg, and cayenne and blend until very smooth (2-3 minutes). Taste and adjust seasonings as desired. You want the sauce to be a bit over-seasoned because it will provide most of the seasoning for the sweet potatoes as well.Toss the sweet potato slices with the sauce in the saucepan or a large bowl, mixing thoroughly but gently to coat all the slices. Arrange slices in stacks the muffin cups to fill them halfway, then sprinkle on half of the cheese. Fill the cups up the rest of the way and sprinkle the remaining cheese on top.Bake for 25-30 minutes, or until the gratins are nicely browned on top and tender when pierced with a fork or toothpick.Cool for at least 10 minutes. Serve hot or warm.