Melt butter in a large skillet over medium heat, then add sliced onions. Cook them slowly, stirring now and then, until they soften and turn golden—this takes about 10–12 minutes.
Deglaze the pan with white wine, scraping up all the tasty bits. Stir in garlic, thyme, salt, and pepper, then cook for another 5 minutes. The onions should be sweet, rich, and caramelized beautifully.
In a measuring cup, whisk together heavy cream, milk, cayenne, salt, and pepper. Stir in the Gruyère cheese and let it melt just slightly. This creamy base doesn’t need to be cooked on the stove—it will thicken in the oven and coat the potatoes perfectly.
Using a mandoline, slice the potatoes thin and even. Generously butter the casserole dish, then pour a small amount of sauce on the bottom.
Add a layer of potatoes, followed by caramelized onions and more sauce. Keep layering until everything is used, finishing with a creamy topping.
Cover the dish with foil and bake at 350°F for 2 hours. This slow cooking allows the potatoes to soak in all the flavors. Remove the foil, sprinkle cheddar cheese over the top, and bake for another 20 minutes. The top should be bubbling and golden brown.
Once baked, sprinkle fresh thyme or parsley over the top for a pop of freshness. Serve hot and enjoy the creamy, cheesy, caramelized goodness in every bite.