refactoring cache implementation