Arrange the oven rack to the middle position in the oven. Preheat oven to 350ºF (177ºC). Butter a 10x15-inch baking dish or spray with nonstick cooking spray; set aside.
In a large skillet, set over medium heat, melt butter (1/4 cup). Add onions (1 cup) and sauté until translucent, about 5 minutes.
Sprinkle flour (1/4 cup) over butter and whisk until it forms a paste. Continue to whisk constantly, cooking for 1-2 minutes, until lightly golden and flour taste has been removed.
Slowly whisk in heavy cream (2 cups) until your mixture is smooth. Whisk in milk (2 cups). Continue to cook, whisking so the mixture doesn't burn until it begins to simmer and thicken.
Stir in salt (1 teaspoon), Cajun seasoning (1 teaspoon), black pepper  (1/4 teaspoon), and nutmeg (1/8 teaspoon).
Remove from heat and stir in Worcestershire (1/4 teaspoon) and fresh thyme leaves (2 teaspoons).
Pour about 1/4 of the sauce into the baking dish. Swirl it around to cover the bottom.
Arrange a layer of sliced potatoes on the bottom, sprinkle with salt, pour 1/4 of the remaining sauce, then sprinkle 1/3 of the grated Cheddar cheese. Arrange 1/2 of the sliced ham over the cheese.
Repeat with a second layer of potatoes and sprinkle again with salt. Ladle the remaining 1/4 of the sauce and sprinkle 1/3 cheddar cheese and the remaining 1/2 of the ham.
Arrange the remaining potatoes on top of the casserole. Ladle the remaining 1/4 of the sauce over the potatoes and spread it out evenly with an offset spatula. Sprinkle the remaining cheese over the top.
Bake the potatoes, uncovered in the preheated oven, until the top is golden brown, and the casserole is bubbling, and the potatoes are very tender, about 1 1/2 to 1 3/4 hours. Let cool for 20 minutes before serving. Garnish with fresh thyme and serve.