Efficient measurement of the time-dependent cavity field through compressed sensing