optimize performance of reference matching by caching