Fixed incorrect module ID caching.

This PR fixes a problem with the module ID cache used by BaseModule::getModuleId(). In some situations, getModuleId() could be called statically from different modules, thus caching only a single module ID - the first one which called getModuleId() - causes a hard to find side effect.