Added caching for apply-rule.