Adds caching infrastructure.

In particular, adds the caching decorator @cache_function(), adds the
app cache, converts the existing caching to use the decorator, and adds
some caching utils.