refactor caching mechanism