Cache matrix implementation