本页面适用于 Apigee 和 Apigee Hybrid。
查看 Apigee Edge 文档。
配置如何从缓存中清除已缓存的值。
此政策适用于通用短期缓存。它与 PopulateCache 政策(用于写入条目)和 LookupCache 政策(用于读取缓存条目)结合使用。
如需了解如何缓存后端资源的响应,请参阅 ResponseCache 政策。
此政策是一项可扩展政策,使用此政策可能会影响费用或使用情况,具体取决于您的 Apigee 许可。如需了解政策类型和使用情况影响,请参阅政策类型。
元素参考
下面列出了您可以在此政策中配置的元素。
<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 属性之外在管理界面代理编辑器中给政策添加不同的自然语言名称标签。
<DisplayName>Policy Display Name</DisplayName>
| 默认 |
不适用 如果省略此元素,则会使用政策的 |
|---|---|
| 状态 | 可选 |
| 类型 | 字符串 |
<CacheContext>/<APIProxyName> 元素
指定添加了缓存条目的应用的名称。
<APIProxyName>application_that_added_the_entry</APIProxyName>
属性
| 属性 | 说明 | 默认值 | 状态 | 类型 |
|---|---|---|---|---|
| ref | 包含应用名称的变量。 | 不适用 | 可选 | 字符串 |
<CacheContext> 元素
指定当未指定 Prefix 元素值时如何构造缓存键,或指定如何清除由其他 API 代理添加的缓存条目。
<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。当 CacheKey 前缀(即自定义前缀)不用于清除其他 API 代理添加的缓存条目时,必须提供 APIProxyName、ProxyName 和 TargetName 的值。
<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> 元素
指定存储消息的缓存。
如果此政策(以及相应的 RePopupCache 和 LookupCache 政策)使用了所包含的共享缓存,请完全忽略此元素。
<CacheResource>cache_to_use</CacheResource>
|
默认: |
不适用 |
|
状态: |
可选 |
|
类型: |
字符串 |
如需详细了解如何配置缓存,请参阅通用缓存。
<CacheKey>/<KeyFragment> 元素
指定应在缓存键中包含的值。使用 ref 特性或固定值指定要取消引用的变量。
<KeyFragment ref="variable_name"/> <KeyFragment>literal_string</KeyFragment>
|
默认: |
不适用 |
|
状态: |
可选 |
|
类型: |
不适用 |
在运行时,Apigee 从 <Scope> 元素或 <Prefix> 元素获取值,并将其作为使用各 <KeyFragment> 元素解析值构成的串联的前缀,从而创建缓存键。如需了解详情,请参阅使用缓存键。
属性
| 属性 | 说明 | 默认值 | 状态 | 类型 |
|---|---|---|---|---|
| ref | 要从中获取值的变量。如果此元素包含字面量值,则不应使用此属性。 | 不适用 | 可选 | 字符串 |
<CacheKey>/<Prefix> 元素
指定要用作缓存键前缀的值。
<Prefix>prefix_string</Prefix>
|
默认: |
不适用 |
|
状态: |
可选 |
|
类型: |
字符串 |
<Prefix> 元素将替换任何 <Scope> 元素。
在运行时,Apigee 从 <Scope> 元素或 <Prefix> 元素获取值,并将其作为使用各 <KeyFragment> 元素解析值构成的串联的前缀,从而创建缓存键。如需了解详情,请参阅使用缓存键。
<CacheContext>/<ProxyName> 元素
指定为其缓存数据的代理的名称。
<ProxyName>proxy_for_which_data_was_cached</ProxyName>
|
默认: |
不适用 |
|
状态: |
可选 |
|
类型: |
字符串 |
属性
| 属性 | 说明 | 默认值 | 状态 | 类型 |
|---|---|---|---|---|
| ref | 要从中获取值的变量。如果此元素包含字面量值,则不应使用此属性。 | 不适用 | 可选 | 字符串 |
<PurgeChildEntries> 元素
true 用于清除缓存条目,这些缓存条目共享为此政策配置的 <Prefix> 值,即使将这些项加载到缓存中的 PopulateCache 政策实例也使用了各种 <KeyFragment> 元素时也是如此。
通过使具有同一前缀值的所有缓存条目失效,您就可以同时完全清除多个相关条目。
<PurgeChildEntries>true_to_purge_child_entries</PurgeChildEntries>
|
默认: |
false |
|
状态: |
可选 |
|
类型: |
布尔值 |
<Scope> 元素
在 <CacheKey> 元素中未提供 <Prefix> 元素时,用于构造缓存键前缀的枚举。
<Scope>scope_enumeration</Scope>
|
默认: |
“专有” |
|
状态: |
可选 |
|
类型: |
字符串 |
<Scope> 设置确定根据 <Scope> 值前置的缓存键。例如,将范围设置为 Exclusive 时,缓存键将采用以下格式:
orgName__envName__applicationName__proxy|TargetName__ [ serializedCacheKey ]。
如果 <CacheKey> 中存在 <Prefix> 元素,则它会取代 <Scope> 元素值。<Scope> 元素的有效值如下所示。
如需了解详情,请参阅使用缓存键。
可接受的值
| 范围值 | 说明 |
|---|---|
Global |
缓存密钥可在环境中部署的所有 API 代理之间共享。缓存键的前置格式为 orgName __ envName __。 如果您使用 |
Application |
API 代理名称用作前缀。 缓存键的前置格式为 orgName__envName__applicationName。 |
Proxy |
ProxyEndpoint 配置用作前缀。 缓存键的前置格式为 orgName__envName__applicationName__proxyEndpointName。 |
Target |
TargetEndpoint 配置用作前缀。 缓存键的前置格式为 orgName__envName__applicationName__targetEndpointName。 |
Exclusive |
默认值。这是最具体的,因此在给定缓存中,可将命名空间冲突降至最低。 前缀采用以下两种格式之一:
缓存键的前置格式为 orgName__envName__applicationName__proxyNameITargetName 例如,完整的字符串可能如下所示: apifactory__test__weatherapi__default__apiAccessToken |
<CacheContext>/<TargetName> 元素
指定为其缓存数据的目标端点的名称。
<TargetName>endpoint_for_which_data_was_cached</TargetName>
|
默认: |
不适用 |
|
状态: |
可选 |
|
类型: |
字符串 |
属性
| 属性 | 说明 | 默认值 | 状态 | 类型 |
|---|---|---|---|---|
| ref | 要从中获取值的变量。如果此元素包含字面量值,则不应使用此属性。 | 不适用 | 可选 | 字符串 |
使用说明
采用 PopulateCache 政策、LookupCache 政策和 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