add general caching mechanism

does not work on expr.solve()