refactor flag cache