Cache match elements to speed up compiler