I want to specify either of two variables in Key fragment in Cache Key,I have two variables which can be a Key fragment in Cache Key

So basically I have two variables in the request and either of which can be the Cache Key in my Cache. I need to Invalidate Cache using either of two variables: request.queryparam.token or request.formparam.token.

Currently I have set Cache Key as below:

<CacheKey>
 <Prefix>apiToken</Prefix>
 <KeyFragment ref="request.queryparam.token"/>
</CacheKey>

But Value of token can either be in queryparam or formparam. Can you please help, its urgent production issue

So basically I want to Invalidate Cache for particular Key. This key can be present in either of the two variables in request that is request.queryparam.token or request.formparam.token.

How can I take both the variables in consideration for removing cache key. Key value would be present in either of two variables.

0 25 349
25 REPLIES 25

Not applicable

request.queryparam.token is the default one in your case.

You can add one assign message policy before the invalidate cache policy. The condition of the policy execution can be

request.formparam.token != ""

and inside the policy, you can set query param as below


<Set>
   <QueryParams>
       <QueryParamname="token">{request.formparam.token}</QueryParam>
   </QueryParams>
</Set>

This will make both the varibales work.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="AM-CopyFormParam"> <DisplayName>AM-CopyFormParam</DisplayName> <Properties/> <Set> <QueryParams> <QueryParam name="token">{request.formparam.token}</QueryParam> </QueryParams> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>

Is this XML correct

Also I have added condition like below:

<Condition>(request.formparam.token !=null AND request.formparam.token !="")</Condition>

Also will this make any changes to request. I don't want my request to be changed by API Gateway

no, this will only set the form param value to query param.

if you want that also not to be changed, then use two assign message policies in which you will set another variable with condition one for queryparam token not null not empty and another formparam token not null not empty. In key fragment use that varibale you have set.

So I should use Set or AssignVariable

So Should Use

<Set> <Name>cache.access.token</Name> <Value>{request.queryparam.token}</Value> </Set>

OR

<AssignVariable> <Name>cache.access.token</Name> <Ref>request.queryparam.token</Ref> </AssignVariable>

Also Instead of making new policies cant we make this part of Invalidate Cache Policy Only assigning variables

You need to add a policy, that makes it simpler. If you don't want to assign the form param variable to the query param, as I specified in the beginning you need to add two policies and assign variables to a new name.

If you will go with the first approach then set query param will work.

<Set> <Name>cache.access.token</Name> <Value>{request.queryparam.token}</Value> </Set> 

doesnot work. its a wrong tag.

We are getting the request.formparam.token value as null even if we pass the token in form parameters and content type as X-url-form-encoded

Please share the policy configuration and trace

Also we have request streaming enabled in APIGEE

There is no way we can extract the value of form Param It Seems so, Now We have used Extract Variable Policy but that's also not working in case of Form Param

EV-FormParam-Token

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-FormParam-Token"> <DisplayName>EV-FormParam-Token</DisplayName> <Properties/> <FormParam name="token"> <Pattern ignoreCase="true">{tokenValue}</Pattern> </FormParam> <QueryParam name="token"> <Pattern ignoreCase="true">{tokenValue}</Pattern> </QueryParam> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <Source clearPayload="false">request</Source> <VariablePrefix>cache</VariablePrefix> </ExtractVariables>

IC-AccessToken

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <InvalidateCache async="false" continueOnError="false" enabled="true" name="IC-AccessToken"> <DisplayName>IC-AccessToken</DisplayName> <Properties/> <CacheKey> <Prefix>apiToken</Prefix> <KeyFragment ref="cache.tokenValue"/> </CacheKey> <CacheResource>OpenAMCache</CacheResource> <Scope>Global</Scope> <CacheContext> <APIProxyName/> <ProxyName>default</ProxyName> <TargetName>default</TargetName> </CacheContext> <PurgeChildEntries>false</PurgeChildEntries> </InvalidateCache>

Not applicable

You are sending the token in the request. You can assign that to a variable using assign message policy. Why are you using extract variable policy?

But I am not able to get the value of my formparams. We are using x-url-form-encoded

Not applicable
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>myvar</Name>
        <Value/>
        <Ref>request.formparam.token</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

you can use above policy to get the form param value.

It is giving blank value I have already tried that

but I tested this works for me. the myvar will have the value you have sent in token form param.

Actualyy we have request.streaming.enabled as true which is causing formparam to have blank Value

In that case you need to desable request streaming and only enable response streaming.

Okay It works. But can we handle this situation via Key Fragments only instead of creating two Assign Messages . Is there anyway to handle this via minimum change

you can follow the first approach, in that you will have to add only one assign message policy.

Okay so do you have any way where we can achieve this without disabling request streaming.

if you can send that in the header is fine. To get through the body you need to disable the request streaming.