Updated code for caching