Database: refactored & optimized getReferencedTable cache logic