Some refactoring to support checking first for cached files.