Updated the caching logic