Re-order cache logic to be more effective