How was the refrigerator invented?

in ancient time the people use ice and snow to preserve the food. Then they think about a machine to cool the food . this leads to the invention of refrigerator.