Implementation of cache matrix