reworked caching logic