Re-factor caching to be modular.