Moved CacheType and CacheKey to inside if block to prevent undef warnings if cache is not activated.