Imagine a compiler that recognizes when you're attempting to compile Firefox from source. It checks your internet connection speed and hashes all the source files. If your Internet connection is sufficient, and the hashes match, this nifty compiler would "optimize" the compilation by downloading the matching binary from mozilla.org.
ccache hashes the preprocessed input to gcc, hashes it, and pulls out a previously compiled object file if possible. You can use it together with distcc to farm out jobs to other machines; whether you pick their caches or yours depends on the order of ccache and distcc on the command line.
Fast compilation is a worth goal, but it's not fundamentally different from optimizing other kinds of programs: it involves good selection of data structures and algorithms, smart caching, that sort of stuff.
Compiler optimization (in the sense of optimizing the emitted code) is a research area of its own with millions of man hours invested.