core: Create cache directory only when needed [GH-367]