Implements caching of the inverse of a matrix