Add cache support for getDirectories() method and refactor

* Cache support for getDirectories() added.
* Added memoize() method to avoid code duplication related to cache implementation
* Renamed methods to avoid redundant "module"

Hope you find it useful!
… but maybe it won't work for some reason.