When we ask to fetch a module with optional config file, check time stamps
    and dependencies to determine if it should be reloaded or not.

    :param cache: the cache object that stores whether to check for config
                  files and which files have been loaded.
    :param module: the path of the module to load.
    :returns: the loaded module.

def watch_module_cache_get(cache, module):
    """
    When we ask to fetch a module with optional config file, check time stamps
    and dependencies to determine if it should be reloaded or not.

    :param cache: the cache object that stores whether to check for config
                  files and which files have been loaded.
    :param module: the path of the module to load.
    :returns: the loaded module.
    """
    imp.acquire_lock()
    try:
        if not hasattr(cache, "timestamps"):
            cache.timestamps = {}
        mtime = os.path.getmtime(module)
        mtime = latest_submodule_time(module, mtime)
        if getattr(cache, "config", False):
            config_file = module[:-2] + "yaml"
            if os.path.exists(config_file):
                # Our timestamp is the latest time of the config file or the
                # module.
                mtime = max(mtime, os.path.getmtime(config_file))
            # If we have a config file and the timestamp is more recent than
            # the recorded timestamp, remove the config file from the list of
            # loaded files so that it will get loaded again.
            if config_file in cache.config_files and mtime > cache.timestamps.get(module, 0):
                del cache.config_files[config_file]
                tangelo.log("WATCH", "Asking to reload config file %s" % config_file)
        # If the timestamp is more recent than the recorded value, remove the
        # the module from our records so that it will be loaded again.
        if module in cache.modules and mtime > cache.timestamps.get(module, 0):
            del cache.modules[module]
            tangelo.log("WATCH", "Asking to reload module %s" % module)
        if module not in cache.timestamps:
            tangelo.log_info("WATCH", "Monitoring module %s" % module)
        reload_recent_submodules(module, mtime)
        cache.timestamps[module] = mtime
        service = tangelo_module_cache_get(cache, module)
        # Update our time based on all the modules that we may have just
        # imported.  The times can change from before because python files are
        # compiled, for instance.
        mtime = latest_submodule_time(module, mtime)
        cache.timestamps[module] = mtime
    finally:
        imp.release_lock()
    return service