CacheMatrix implementation