Created cachematris function.