With a bit of nudging from Vas I dug a bit deeper. I think it is a bug in part_of_mediapath.
The if condition is this if (path.compare(mediapath.substr(0, mediapath.length())))
Probably should be this if (mediapath.compare(path.substr(0, mediapath.length())) == 0)
It is comparing the wrong parts of the string and not checking for the 0 result. I think the intent is to keep it to the rompath dirs. However it is pretty much always letting it through.
This is as fast as my cache way. There are a couple of other minor tweaks that could be made. But those do not do anything significant.
The second cache I added breaks the ability to add files/dirs randomly. It is about 8x faster but I am going to leave it as experimental. Samba shares are apparently really bad if you have a path_not_found miss.