refactoring: factor out code for cache refreshing