Freeze water into ice. Enclose items in ice to slow spoiling. Store spoilables in a refrigerator to stop spoiling completely. Fridges draw power based on ambient temperature. Also adds cooled wagons.
Can't be coded reasonably to melt depending on temperature. Tracking items on such a scale is practically not possible. Only setting ice cubes to spoil generally is doable.