Corrected caching logic