wrote body of "cache" function