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!