Cache matrix functions.