<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def by_name(self, name):
 """ In many cases you want to access directory not by it's ID, but by it's name. This method implements red-black search method, which internally uses CFB format. Also this method has internal name cache to speed up 2nd+ named accesses. """

        if name in self._name_cache:
            return self[self._name_cache[name]]

        if self.source.root.name == name:
            return self.source.root
        current = self.source.root.child

        while current:
            if len(current.name) < len(name):
                current = current.right
            elif len(current.name) > len(name):
                current = current.left
            elif current.name < name:
                current = current.right
            elif current.name > name:
                current = current.left
            else:
                return current

        raise KeyError(name)