Cache root ID for nested sets table

The root ID of a nested sets table is highly unlikely to change within a single page load of the site. When there are potentially multiple queries being executed to determine the root ID, this can become redundant work on a popular tree. To avoid this, once we have determined the root ID for a given table-key combination, the code will cache it internally and return that later reducing the number of times that redundant queries need to be executed.