fix caching for GSMat and GMat