Implement cached matrix inversion

First implementation of cached matrix inversion routine.