

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 關閉步驟快取
<a name="pipelines-caching-disabling"></a>

如果您變更任何未針對其步驟類型在 [依管道步驟類型的預設快取金鑰屬性](pipelines-default-keys.md) 中列出的屬性，管道步驟不會重新執行。不過，您可能會決定仍然要重新執行管道步驟。在這種情況下，您需要關閉步驟快取。

若要關閉步驟快取，請在步驟定義中將步驟定義之 `CacheConfig` 屬性中的 `Enabled` 屬性設定為 `false`，如下列程式碼片段所示：

```
{
    "CacheConfig": {
        "Enabled": false,
        "ExpireAfter": "<time>"
    }
}
```

請注意，如果 `Enabled` 為 `false`，則 `ExpireAfter` 屬性會被忽略。

若要使用 Amazon SageMaker Python SDK 為管道步驟關閉快取，請定義管道步驟的管道、關閉 `enable_caching` 屬性，然後更新管道。

再次執行後，下列程式碼範例會為訓練步驟關閉快取：

```
from sagemaker.workflow.pipeline_context import PipelineSession
from sagemaker.workflow.steps import CacheConfig
from sagemaker.workflow.pipeline import Pipeline

cache_config = CacheConfig(enable_caching=False, expire_after="PT1H")
estimator = Estimator(..., sagemaker_session=PipelineSession())

step_train = TrainingStep(
    name="TrainAbaloneModel",
    step_args=estimator.fit(inputs=inputs),
    cache_config=cache_config
)

# define pipeline
pipeline = Pipeline(
    steps=[step_train]
)

# update the pipeline
pipeline.update()
# or, call upsert() to update the pipeline
# pipeline.upsert()
```

或者，在定義管道之後關閉 `enable_caching` 屬性，允許一次持續的程式碼執行。下列程式碼範例會示範此解決方案：

```
# turn off caching for the training step
pipeline.steps[0].cache_config.enable_caching = False

# update the pipeline
pipeline.update()
# or, call upsert() to update the pipeline
# pipeline.upsert()
```

如需有關 Python SDK 參數如何影響快取的詳細程式碼範例和討論，請參閱 Amazon SageMaker Python SDK 文件中的 [Caching Configuration](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#caching-configuration)。