Add cached matrix implementation