A thermodynamically consistent model for cavitating flows of compressible fluids