implemement matrix solver with cache