The main reason food needed to be preserved before the advent of electric refrigerators was to slow the action of bacteria and mold which caused food to spoil and could even be dangerous to people who ate the food.
One method was pickling surplus vegetables. By placing cucumbers for example, in a brine with salt and vinegar and spices and then placing in vacuum sealed jars, the pickled items would last a very long time.
If it was cold during the winter months, ice could be put into an "ice box" in a large chunk to keep foods cool. Streams could be used to keep beverages and food cool and if a cave was nearby, their naturally cool and stable environments are ideal to keep food from spoiling. Produce could be stored in a cool, dry environment such as in a cellar or basement to extend how long fresh produce or canned items could last.
Salting was another method of preservation. By salting and thus drying the food, it prevented the food from spoiling and slowed bacterial action. Salted codfish can still be bought today and when ready to use, it can be washed and soaked to remove the salt and soften it once again before cooking.
Drying meat to make beef jerky as an example, could allow the food to last very long and it could be eaten that way, or reconstituted when soaked in water. Produce like beans can be stored when dried for many months and fruits can be dried out and stored for a very long time as well.
Smoking meats has long been a method of preservation. Items like bacon, ham, fish and others are made by smoking over a low flame for a very long time. The smoking is a preservative which extends the shelf life of meats.
Using the action of microbes, fermentation is a process which can extend the shelf life of foods. An example is the making of wine from grapes or beer from grains. The alcohol produced by fermentation performed by microbes known as yeasts can allow these beverages to last a very long time. Fermented foods are also healthy-- sauerkraut can be made with lactic acid bacteria which are able to ferment the cabbage because starch and sugar are present in the leaves. The sauerkraut can last a longer length of time than the fresh cabbage would and can be stored.
The production of jelly or jam with some of the excess fruit crop would be used to preserve rather than have to discard fruit that spoiled quickly. The fruit would be boiled with sugar and cooked down and later placed in jars which were vacuum sealed. These fruits would be preserved for later use and would not easily spoil.
These are some methods people used before refrigeration and to a great extent still use today in the constant struggle to maintain our food supply.