Fixed error in caching logic