Refactor use of cache