Cleanup cache implementation, and add per-use configuration.