Added caching functionality  to calculate inverse of a matrix