Preheat oven to 375°F and butter a large 3-quart casserole dish.
Melt 2 tbsp butter in a large skillet over medium-high heat until starting to foam. Add mushroom and cook until lightly browned and the moisture has evaporated. Add minced garlic and continue to cook, stirring often for 1-2 minutes. Season with salt and pepper. Remove to a clean bowl.
Melt another 1-2 tbsp of butter over medium heat and add sliced onions. Sprinkle with salt and sauté for 4-5 minutes until starting to soften.
While mushrooms and onions are cooking, whisk together cream, sour cream, salt, pepper and nutmeg. In a separate bowl whisk together milk and flour until smooth. Add to the sour cream mixture and whisk until incorporated. Grate the cheese and set it aside.
Peel and thinly slice the potatoes and dab dry with a paper towel. Spread half of the potato slices evenly in the bottom of the prepared casserole dish. Scatter half of the sauteed mushrooms and onions over the potatoes. Top evenly with half of the cheese. Repeat with remaining potatoes, mushrooms and cheese.
Pour the cream mixture evenly over the potatoes. Give the pan a gentle shake to help flatten everything out. Cover and bake for 45-60 minutes. Start checking at 45 minutes. The potatoes should be 'just' tender in the center. Remove the cover and bake for an additional 20 minutes until the top is golden and the potatoes are cooked through.
Remove from oven, cover and allow to rest for 10 minutes before serving. Garnish with chopped fresh parsley or sliced green onions if desired.
