Adding code to handle cache writes