implementation of cached inverse matrix