Functions for calculating inverse; if it is already calculated, it
just returns from cache. Else it calculates the inverse and populates
the cache. I used solve() function for the inverse