如何在Mule4中生成用于访问令牌的缓存密钥?

问题描述 投票:0回答:1

我已经使用默认的密钥生成过程配置了我的缓存范围。它在缓存范围中缓存accesstoken我将这种缓存逻辑分开保存。

例如:

<os:object-store name="Object_store" doc:name="Object store" persistent="false" maxEntries="10" entryTtl="7" entryTtlUnit="HOURS" expirationIntervalUnit="HOURS"/>
    <ee:object-store-caching-strategy
        name="Caching_Strategy" doc:name="Caching Strategy" objectStore="Object_store" />
    <flow name="sys-caching:\tokenFlow">
        <ee:cache doc:name="Cache"  cachingStrategy-ref="Caching_Strategy">
            <flow-ref doc:name="getchallenge"  name="sys-authentication:\get-challenge-subflow"/>
            <flow-ref doc:name="getaccesstoken"name="sys-authentication:\get-token-subflow"/>
        </ee:cache>
</flow>

我在使用外部端点进行GET / POST调用时,在不同的情况下在缓存流上方调用(以获得访问令牌)。我的问题是,每次缓存范围的有效负载都不相同。因此,它将进行新的调用以获取新令牌,并且将缓存更多令牌。如果有效载荷相同,则缓存返回相同的令牌。

我的requiremnet是,不依赖有效负载。。只需返回缓存的访问令牌8个小时(缓存期)如何为此配置缓存密钥?

mule mule-studio mule-component mulesoft
1个回答
0
投票

使用keyGenerationExpression属性为缓存定义自定义键。

示例:

keyGenerationExpression="#[vars.requestId]"
© www.soinside.com 2019 - 2024. All rights reserved.