Giant magnetocaloric effects by tailoring the phase transitions