implement cache reading and writing.