implementation of cachematrix