Implementation of the cache matrix functions