Add invalidate function to improve performance