查看 Apigee Edge 說明文件。
前往
Apigee X說明文件。 資訊

設定應在執行階段寫入快取值的方式。
「填入快取」政策是專為在短期的一般用途快取中寫入項目而設計。 會搭配 Lookup 使用 快取政策 (用於讀取快取項目) 和 撤銷快取政策 (用於撤銷項目)。
如要快取後端資源的回應,請參閱 回應快取政策:
元素參照
以下列出您可以為這項政策設定的元素。
<PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Cache-1"> <DisplayName>Populate Cache 1</DisplayName> <Properties/> <CacheKey> <Prefix/> <KeyFragment ref=""/> </CacheKey> <!-- Omit this element if you're using the included shared cache. --> <CacheResource/> <Scope>Exclusive</Scope> <ExpirySettings> <TimeoutInSeconds>300</TimeoutInSeconds> </ExpirySettings> <Source>flowVar</Source> </PopulateCache>
<PopulateCache>屬性
下表說明所有政策父項元素的共同屬性:
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
name |
政策的內部名稱。 視需要使用 |
不適用 | 必填 |
continueOnError |
如果設為「 如果設為 |
false | 選用 |
enabled |
如要強制執行政策,請設為 設為 |
true | 選用 |
async |
此屬性已淘汰。 |
false | 已淘汰 |
<DisplayName>元素
除 name
屬性外,一併使用
管理 UI Proxy 編輯器,使用不同的自然語言名稱。
<DisplayName>Policy Display Name</DisplayName>
預設 |
不適用 如果省略這個元素,政策的 |
---|---|
存在必要性 | 選用 |
類型 | 字串 |
<CacheKey>元素
設定儲存在快取中資料的唯一指標。
快取金鑰的大小上限為 2 KB。
<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>元素
指定應儲存訊息的快取。
如果這項政策 (以及您的對應 LookupCache 與 InvalidateCache 政策) 使用的是隨附共用快取。
<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>
。詳情請參閱使用快取金鑰。
<ExpirySettings>元素
指定快取項目的到期時間。時間
目前存在,<TimeoutInSeconds>
項覆寫
<TimeOfDay>
和 <ExpiryDate>
兩者。
<ExpirySettings> <!-- use exactly one of the following child elements --> <TimeoutInSeconds ref="duration_variable">seconds_until_expiration</TimeoutInSeconds> <ExpiryDate ref="date_variable">expiration_date</ExpiryDate> <TimeOfDay ref="time_variable">expiration_time</TimeOfDay> </ExpirySettings>
預設: |
不適用 |
所在地: |
必填 |
類型: |
不適用 |
<ExpirySettings>
的子元素
您只能使用一個子元素。下表提供
<ExpirySettings>
:
子元素 | 說明 |
---|---|
<TimeoutInSeconds> |
快取項目的到期時間 (以秒為單位)。 <ExpirySettings> <TimeoutInSeconds ref="var-containing-duration">expiry</TimeoutInSeconds> </ExpirySettings> 這個元素會取代現已淘汰的 |
<ExpiryDate> |
指定快取項目的到期日。請以下列格式指定字串
<ExpirySettings> <ExpiryDate ref="var-containing-date">expiry</ExpiryDate> </ExpirySettings> 如果指定的日期是過去的日期,政策就會套用 存留時間上限 (TTL)。最長不得超過 30 天。 |
<TimeOfDay> |
指定快取項目的到期時間。
以 <ExpirySettings> <TimeOfDay ref="var-containing-time">expiry</TimeOfDay> </ExpirySettings> |
您只能指定其中一項可能的子元素。如果要指定多個元素
優先順序為:TimeoutInSeconds
、ExpiryDate
、
TimeOfDay
。
透過 <ExpirySettings>
的上述每個子元素,
如果您為子項元素指定 ref
的選用屬性,則這項政策會
從已命名的結構定義變數中擷取到期時間值。如果未定義變數
這項政策會使用子項元素的常值文字值。
<Scope>元素
在 <Prefix>
時,用於建構快取金鑰的前置字串的列舉
未在 <CacheKey>
元素中提供。
<Scope>scope_enumeration</Scope>
預設: |
「獨家」 |
所在地: |
選用 |
類型: |
字串 |
<Scope>
設定會決定系統會根據
<Scope>
值。舉例來說,快取金鑰採用以下格式時
範圍設為 Exclusive
:
orgName__envName__apiProxyName__deployedRevisionNumber__proxy|TargetName__ [ serializedCacheKey ]
如果 <CacheKey>
中有 <Prefix>
元素,
會取代 <Scope>
元素值。有效值包括列舉值
。
請將 <Scope>
元素與
<CacheKey>
和<Prefix>
。詳情請參閱使用快取金鑰。
可接受的值
Global |
部署於環境中的所有 API Proxy 會共用快取金鑰。快取金鑰為 前面加上 orgName __ envName __。 如果您使用 |
Application |
系統會使用 API Proxy 名稱做為前置字串。 快取金鑰的前置字串為 orgName__envName__apiProxyName。 |
Proxy |
系統會使用 ProxyEndpoint 設定做為前置字串。 快取金鑰會加在下列格式中 orgName__envName__apiProxyName__deployedRevisionNumber__proxyEndpointName。 |
Target |
目標端點設定會用作前置字串。 表單前面加上的快取金鑰 orgName__envName__apiProxyName__deployedRevisionNumber__targetEndpointName。 |
Exclusive |
預設。這是最具體的,因此對命名空間帶來的風險最低 特定快取中的衝突。 前置字串為兩種形式之一:
表單前面加上的快取金鑰 orgName__envName__apiProxyName__deployedRevisionNumber__proxyNameITargetName 舉例來說,完整字串可能如下所示: apifactory__test__weatherapi__16__default__apiAccessToken |
<Source>元素
指定應將值寫入快取的變數。
<Source>source_variable</Source>
預設: |
不適用 |
所在地: |
必填 |
類型: |
字串 |
使用須知
請將這項政策用於一般用途快取。在執行階段中,
<PopulateCache>
政策會從您在
<Source>
元素設為您在
<CacheResource>
元素。您可以使用 <CacheKey>
、
<Scope>
和 <Prefix>
元素,藉此指定您
可使用 <LookupCache>
政策擷取值。使用
<ExpirySettings>
元素,設定快取值的到期時間。
使用 PopulateCache 政策、LookupCache 政策和 InvalidateCache 政策進行一般用途快取
您設定的快取或預設包含的共用快取。在大多數的情況下,
基本共用快取就能滿足需求如要使用這個快取,只要省略
<CacheResource>
元素。
快取限制:各種快取限制 例如名稱和值大小、快取總數、快取中的項目數量 以及到期日
如要進一步瞭解基礎資料儲存庫,請參閱「快取內部」。進一步瞭解如何設定 快取,請參閱建立及編輯 環境快取。
關於快取加密
公有雲的邊緣:快取只會在 PCI: 且已啟用 HIPAA 員工只能在您的 Google Cloud 機構中存取資源 無法在其他機構存取資源已在組織期間設定這些機構的加密機制 佈建工作
錯誤代碼
This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
Runtime errors
These errors can occur when the policy executes.
Fault code | HTTP Status | Occurs when |
---|---|---|
policies.populatecache.EntryCannotBeCached |
500 | An entry cannot be cached. The message object being cached is not an instance of a class that is Serializable. |
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 PopulateCache policy is set to
a name that does not exist in the environment where the API proxy is being deployed. |
build |
CacheNotFound |
The cache specified in the <CacheResource> element does not
exist. |
build |
Fault variables
These variables are set when this policy triggers an error. For more information, see What you need to know about policy errors.
Variables | Where | Example |
---|---|---|
fault.name="fault_name" |
fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. | fault.name = "EntryCannotBeCached" |
populatecache.policy_name.failed |
policy_name is the user-specified name of the policy that threw the fault. | populatecache.POP-CACHE-1.failed = true |
Example error response
{ "fault": { "faultstring": "[entry] can not be cached. Only serializable entries are cached.", "detail": { "errorcode": "steps.populatecache.EntryCannotBeCached" } } }
Example fault rule
<FaultRule name="Populate Cache Fault"> <Step> <Name>AM-EntryCannotBeCached</Name> <Condition>(fault.name Matches "EntryCannotBeCached") </Condition> </Step> <Condition>(populatecache.POP-CACHE-1.failed = true) </Condition> </FaultRule>