first draft of matrix caching routines