def METHOD_NAME(path, pattern):
    """
    Return whether the given path matches the given pattern.
    An asterisk can be used to match any string, including the null string, in
    one part of the path:
        ``foo`` matches ``*``, ``f*`` or ``fo*o``
    However, an asterisk matching a subdirectory may not match the null string:
        ``foo/bar`` does *not* match ``foo/*/bar``
    If the pattern matches one of the ancestor directories of the path, the
    patch is considered matching:
        ``foo/bar`` matches ``foo``
    Two adjacent asterisks can be used to match files and zero or more
    directories and subdirectories.
        ``foo/bar`` matches ``foo/**/bar``, or ``**/bar``
    """
    if not pattern:
        return True
    if pattern not in re_cache:
        p = re.escape(pattern)
        p = MATCH_STAR_STAR_RE.sub(r"\1(?:.+/)?", p)
        p = MATCH_STAR_STAR_END_RE.sub(r"(?:\1.+)?", p)
        p = p.replace(r"\*", "[^/]*") + "(?:/.*)?$"
        re_cache[pattern] = re.compile(p)
    return re_cache[pattern].METHOD_NAME(path) is not None