

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 关闭步骤缓存
<a name="pipelines-caching-disabling"></a>

如果您更改未在 [按管道步骤类型划分的默认缓存键属性](pipelines-default-keys.md) 中列出的管道步骤类型的任何属性，则不会重新运行该管道步骤。不过，您可能会决定无论如何都要重新运行该管道步骤。在这种情况下，您需要关闭步骤缓存。

要关闭步骤缓存，请将步骤定义的 `CacheConfig` 属性中的 `Enabled` 属性设置为 `false`，如以下代码片段所示：

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

请注意，当 `Enabled` 为 `false` 时，将忽略 `ExpireAfter` 属性。

要使用 Amaz SageMaker on 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 软件开发工具包参数如何影响缓存的讨论，请参阅 Amaz SageMaker on Python 软件开发工具包文档中的[缓存配置](https://sagemaker.readthedocs.io/en/stable/amazon_sagemaker_model_building_pipeline.html#caching-configuration)。