#1007 added caching to prevent duplicate directory scanning