Fixed a bug in the caching logic