generator: refactor access to IntermediateModelsCache - extract helper to keep knowledge about cache initialization and use.