add cache and cleanup cache function