implement the functions of caching matrix