Update code to cache matrix value.