查看 Apigee Edge 說明文件。
前往
Apigee X說明文件。 資訊
設定如何從快取中清除快取值。
這項政策適用於一般用途的短期快取,用於 搭配 Populate 快取政策 (用於寫入項目) 和查詢快取政策 (用於讀取快取項目)。
如要快取後端資源的回應,請參閱 回應快取政策:
元素參照
以下列出您可以為這項政策設定的元素。
<InvalidateCache async="false" continueOnError="false" enabled="true" name="policy-name"> <DisplayName>Policy Name</DisplayName> <CacheKey> <Prefix>prefix_string</Prefix> <KeyFragment ref="variable_reference"/> <KeyFragment>fragment_string</KeyFragment> </CacheKey> <!-- Omit this element if you're using the included shared cache. --> <CacheResource>cache_to_use</CacheResource> <Scope>scope_enumeration</Scope> <CacheContext> <APIProxyName>application_that_added_the_entry</APIProxyName> <ProxyName>proxy_for_which_data_was_cached</ProxyName> <TargetName>endpoint_for_which_data_was_cached</TargetName> </CacheContext> <PurgeChildEntries>true_to_purge_all_child_entries</PurgeChildEntries> </InvalidateCache>
<InvalidateCache>屬性
下表說明所有政策父項元素的共同屬性:
| 屬性 | 說明 | 預設 | 存在必要性 |
|---|---|---|---|
name |
政策的內部名稱。 視需要使用 |
不適用 | 必填 |
continueOnError |
如果設為「 如果設為 |
false | 選用 |
enabled |
如要強制執行政策,請設為 設為 |
true | 選用 |
async |
此屬性已淘汰。 |
false | 已淘汰 |
<DisplayName>元素
除 name 屬性外,一併使用
管理 UI Proxy 編輯器,使用不同的自然語言名稱。
<DisplayName>Policy Display Name</DisplayName>
| 預設 |
不適用 如果省略這個元素,政策的 |
|---|---|
| 存在必要性 | 選用 |
| 類型 | 字串 |
<CacheContext>/<APIProxyName>元素
指定新增快取項目的應用程式名稱。
<APIProxyName>application_that_added_the_entry</APIProxyName>
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 參考資料 | 包含應用程式名稱的變數。 | 不適用 | 選用 | 字串 |
<CacheContext>元素
指定在 Prefix 元素值非可用時建構快取金鑰的方式
或清除其他 API Proxy 新增的快取項目。
<CacheContext> <APIProxyName ref="variable_name">application_that_added_the_entry</APIProxyName> <TargetName ref="variable_name">endpoint_for_which_data_was_cached</TargetName> <ProxyName ref="variable_name">proxy_for_which_data_was_cached</ProxyName> </CacheContext>
用於建構 CacheKey。APIProxyName、ProxyName 和 TargetName 的值為 如果不使用 CacheKey 前置字串 (也就是自訂的前置字串) 來清除快取項目,就會強制要求 其他 API Proxy 所新增的 IP 位址。
<CacheKey>元素
設定儲存在快取中資料的唯一指標。
<CacheKey> <Prefix>string</Prefix> <KeyFragment ref="variable_name" /> <KeyFragment>literal_string</KeyFragment> </CacheKey>
|
預設: |
不適用 |
|
所在地: |
必填 |
|
類型: |
不適用 |
<CacheKey> 會建立儲存在
快取。
在執行階段,<KeyFragment> 值會在前面加上
<Scope> 元素值或 <Prefix> 值。舉例來說,
產生的快取金鑰
UserToken__apiAccessToken__<value_of_client_id>:
<CacheKey>
<Prefix>UserToken</Prefix>
<KeyFragment>apiAccessToken</KeyFragment>
<KeyFragment ref="request.queryparam.client_id" />
</CacheKey>請將 <CacheKey> 元素與
<Prefix>和<Scope>。詳情請參閱使用快取金鑰。
<CacheResource>元素
指定應儲存訊息的快取。
如果這項政策 (以及對應的 PopulateCache 與 LookupCache 政策) 使用的是納入的共用快取。
<CacheResource>cache_to_use</CacheResource>
|
預設: |
不適用 |
|
所在地: |
選用 |
|
類型: |
字串 |
如要進一步瞭解如何設定快取,請參閱建立及編輯環境 快取。
<CacheKey>/<KeyFragment>元素
指定要納入快取金鑰的值,建立用來比對的命名空間 快取回應產生的要求。
<KeyFragment ref="variable_name"/> <KeyFragment>literal_string</KeyFragment>
|
預設: |
不適用 |
|
所在地: |
選用 |
|
類型: |
不適用 |
這可以是鍵 (您提供的靜態名稱) 或值 (由 參照變數)。所有指定片段組合 (加上前置字串) 都會串連 建立快取金鑰
<KeyFragment>apiAccessToken</KeyFragment> <KeyFragment ref="request.queryparam.client_id" />
請將 <KeyFragment> 元素與
<Prefix>和<Scope>。詳情請參閱使用快取金鑰。
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 參考資料 | 用來取得值的變數。如果這個元素包含 常值。 | 不適用 | 選用 | 字串 |
<CacheKey>/<Prefix>元素
指定要做為快取金鑰前置字串的值。
<Prefix>prefix_string</Prefix>
|
預設: |
不適用 |
|
所在地: |
選用 |
|
類型: |
字串 |
如要指定自己的值,請使用這個值,而非 <Scope>
而非 <Scope> 列舉值。如已定義
<Prefix> 會在寫入快取的項目前面加上快取金鑰值。A 罩杯
<Prefix> 元素值會覆寫 <Scope> 元素
值。
請將 <Prefix> 元素與
<CacheKey>和<Scope>。詳情請參閱使用快取金鑰。
<CacheContext>/<ProxyName>元素
指定快取資料的 Proxy 名稱。
<ProxyName>proxy_for_which_data_was_cached</ProxyName>
|
預設: |
不適用 |
|
所在地: |
選用 |
|
類型: |
字串 |
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 參考資料 | 用來取得值的變數。如果這個元素包含 常值。 | 不適用 | 選用 | 字串 |
<PurgeChildEntries>元素
true:清除共用由
已為這項政策設定 <KeyFragment> 元素。在
快取金鑰不包括在 <Prefix> 元素中。
請注意,必須指定 <KeyFragment> 元素。如果不是
將 <PurgeChildEntries> 設為 true 時,系統可能會清除以下值區的所有項目:
快取。
撤銷相同鍵片段值的所有快取項目,有效 一次清除多個相關項目。
<PurgeChildEntries>true_to_purge_child_entries</PurgeChildEntries>
|
預設: |
false |
|
所在地: |
選用 |
|
類型: |
布林值 |
<Scope>元素
在 <Prefix> 時,用於建構快取金鑰的前置字串的列舉
未在 <CacheKey> 元素中提供。
<Scope>scope_enumeration</Scope>
|
預設: |
「獨家」 |
|
所在地: |
選用 |
|
類型: |
字串 |
<Scope> 設定會決定系統會根據
<Scope> 值。舉例來說,快取金鑰採用以下格式時
範圍設為 Exclusive:
orgName__envName__applicationName__deployedRevisionNumber__proxy|TargetName__ [serializedCacheKey]。
如果 <CacheKey> 中有 <Prefix> 元素,
會取代 <Scope> 元素值。有效值包括列舉值
。
請將 <Scope> 元素與
<CacheKey>和<Prefix>。詳情請參閱使用快取金鑰。
可接受的值
| 範圍值 | 說明 |
|---|---|
Global |
部署於環境中的所有 API Proxy 會共用快取金鑰。快取金鑰為 前面加上 orgName __ envName __。 如果您使用 |
Application |
系統會使用 API Proxy 名稱做為前置字串。 快取金鑰會加在下列格式中 orgName__envName__applicationName. |
Proxy |
系統會使用 ProxyEndpoint 設定做為前置字串。 快取金鑰會加在下列格式中 orgName__envName__applicationName__deployedRevisionNumber__proxyEndpointName ,直接在 Google Cloud 控制台實際操作。 |
Target |
目標端點設定會用作前置字串。 表單前面加上的快取金鑰 orgName__envName__applicationName__deployedRevisionNumber__targetEndpointName ,直接在 Google Cloud 控制台實際操作。 |
Exclusive |
預設。這是最具體的,因此對命名空間帶來的風險最低 特定快取中的衝突。 前置字串為兩種形式之一:
表單前面加上的快取金鑰 orgName__envName__applicationName__deployedRevisionNumber__proxyNameITargetName 舉例來說,完整字串可能如下所示: apifactory__test__weatherapi__16__default__apiAccessToken |
<CacheContext>/<TargetName>元素
指定快取資料的目標端點名稱。
<TargetName>endpoint_for_which_data_was_cached</TargetName>
|
預設: |
不適用 |
|
所在地: |
選用 |
|
類型: |
字串 |
屬性
| 屬性 | 說明 | 預設 | 存在必要性 | 類型 |
|---|---|---|---|---|
| 參考資料 | 用來取得值的變數。如果這個元素包含 常值。 | 不適用 | 選用 | 字串 |
使用須知
使用填入快取政策、查詢快取政策和
InvalidateCache 政策會使用您設定的快取,或包含在以下項目的共用快取:
預設值。在大部分情況下,基礎共用快取應能滿足您的需求。如要使用這個快取
只要省略 <CacheResource> 元素即可。
如要進一步瞭解如何設定快取,請參閱建立及編輯環境 快取。如要進一步瞭解基礎資料儲存庫,請參閱「快取內部」。
錯誤代碼
This section describes the error messages and flow variables that are set when this policy triggers an error. This information is important to know if you are developing fault rules for a proxy. To learn more, see What you need to know about policy errors and Handling faults.
Error code prefix
N/A
Runtime errors
This policy does not throw any runtime errors.
Deployment errors
These errors can occur when you deploy a proxy containing this policy.
| Error name | Cause | Fix |
|---|---|---|
InvalidCacheResourceReference |
This error occurs if the <CacheResource> element in the InvalidateCache policy is set
to a name that does not exist in the environment where the API proxy is being deployed. |
build |
CacheNotFound |
This error occurs if the specific cache mentioned in the error message has not been created on a specific Message Processor component. | build |
Fault variables
N/A
Example error response
N/A