Smart caching refactoring