implement CacheMatrix functionality