A generalized magnetic refrigeration scheme