Add preprocessor conditionals for caching and logging

Easily switch off code for caching/logging using these conditionals.