move cache related code to cache class.