Solid-state emitters are excellent candidates for developing integrated sources of single photons. Yet, phonons degrade the photon indistinguishability both through pure dephasing of the zero-phonon line and through phonon-assisted emission. Here, we study theoretically and experimentally the indistinguishability of photons emitted by a semiconductor quantum dot in a microcavity as a function of temperature. We show that a large coupling to a high quality factor cavity can simultaneously reduce the effect of both phonon-induced sources of decoherence. It first limits the effect of pure dephasing on the zero phonon line with indistinguishabilities above $97%$ up to $18$ K. Moreover, it efficiently redirects the phonon sidebands into the zero-phonon line and brings the indistinguishability of the full emission spectrum from $87%$ (resp. $24%$) without cavity effect to more than $99%$ (resp. $76%$) at $0$ K (resp. $20$ K). We provide guidelines for optimal cavity designs that further minimize the phonon-induced decoherence.