Heat 50g butter in a frying pan and add the onions and a pinch of salt. Cook on a medium heat until the onions are translucent and, then reduce the heat and add the thyme.
Cook gently for 20 minutes, stirring regularly, until the onions are really soft, sticky and caramelised. Add the beef stock and boil until syrupy.
Heat a pan over a medium heat. Spread the remaining butter on one side of every slice of bread, and divide the grated cheese and caramelised onions between four of the pieces. Place a buttered slice of bread on top of each cheese and onion slice and butter the top of the sandwich.
Place into the hot pan, flipping the sandwich so it goes in buttered side down. Butter the side that is now facing up and place a few thyme sprigs on top. Place a cast iron pan on top of the sandwich to weight down and fry for 3 - 4 minutes on each side. Serve immediately.