implementation of cachable matrix