export middleware and invalidate