Thermal and electronic nonlinearities in semiconductor cavities