Periodically refreshed quantum thermal machines