Optimize caching rule matching.