caching already calculated prefix context in rules expansion