Dispersion relations in real and virtual Compton scattering