How does gas cool in dark matter haloes?