Feature/flush cookie based on #313

Cherry pick commit from  Exposing flushcookie api. #313, manually fix merge issues and rename interface to make a little more consistent.