For learning purposes, added code for validating the function. The validation also shows the time difference between calculating inverse and retrieving from cache