Refactor the cache iterators by using a common base class