lookup cache is not working as expected

Hi, I'm facing an issue where I'm unable to get a cached value using lookup cache policy as explained below:

I have two API Proxies

1) Authentication API Proxy

2) Get Account Details Proxy

1) Authentication API Proxy is called to generate Apigee Access Token

2) In the Get Account Details Proxy we will first verify the apigee generated access token in the proxy pre-flow and in the target pre-flow we set up few policies to call the backed API to return the account details.

Everything works as expected with above flow but the only problem is that the actual back end API is openly accessible.

So the API developers are planning to secure the backed API using OAuth. They have their own OAuth Server which will issue an access token specific to their system. Now the new ask is that during the Get Account Details Proxy Flow we need to make a call their external OAuth endpoint by passing External client ID, Client Secret, Username & Password (All these are specific to their OAuth Server) and it returns a response with access token in it.

To achieve this I have implemented the following withing the second proxy:

1) Service Callout Policy - Sets the headers and calls the target OAuth endpoint

2) Extract Access Token Policy - Extracts the access token from the response received from service callout

3) Populate Cache - Populate the cache with the access token received

4) Lookup Cache - To lookup the access token within the cache Service call out policy,

Service CallOut, Extract Access Token Policy & Populate Cache Policies works just fine however the lookup cache policy always returns false or returns the value of the apigee access token (Step 1).

Can you please help me fix the lookup cache policy to fetch the external access token?

Below are how the Extract token, lookup and populate cache polices look like

Extract Token Policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="ExtractAccessSFDCAccessToken">
    <DisplayName>ExtractAccessSFDCAccessToken</DisplayName>
    <Properties/>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="sfdc_access_token">
            <JSONPath>$.access_token</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">SFDCOAuthResponse</Source>
    <!--<VariablePrefix>SFDCToken</VariablePrefix> -->
</ExtractVariables>
<br>

Populate Cache Policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" name="PopulateSFDCOAuthAccessToken">
    <DisplayName>PopulateSFDCOAuthAccessToken</DisplayName>
    <Properties/>
    <CacheResource>SFDCAccessToken</CacheResource>
    <CacheKey>
        <KeyFragment ref="access_token"/>
        <Prefix/>
        <!-- <KeyFragment ref=""/> -->
    </CacheKey>
    <Scope>Global</Scope>
    <!--<ExpirySettings>
        <TimeoutInSec>82800</TimeoutInSec>
    </ExpirySettings> -->
    <Source>sfdc_access_token</Source>
</PopulateCache>

Lookup Cache Policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="LookupSFDCAccessToken">
    <DisplayName>LookupSFDCAccessToken</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment ref="access_token"/>
    </CacheKey>
    <CacheResource>SFDCAccessToken</CacheResource>
    <Scope>Global</Scope>
    <AssignTo>sfdc_access_token</AssignTo>
</LookupCache>

Default XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="LookupSFDCAccessToken">
    <DisplayName>LookupSFDCAccessToken</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment ref="access_token"/>
    </CacheKey>
    <CacheResource>SFDCAccessToken</CacheResource>
    <Scope>Global</Scope>
    <AssignTo>sfdc_access_token</AssignTo>
</LookupCache>
0 3 513
3 REPLIES 3

Below is the default XML (Please disregard default XML in above question):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>LookupSFDCAccessToken</Name>
            </Step>
            <Step>
                <Name>KVMToGetCredentials</Name>
            </Step>
            <Step>
                <Name>SC_SFDC_OAuth_Target</Name>
                <Condition>lookupcache.LookupSFDCAccessToken.cachehit = "false"
		        </Condition>
            </Step>
            <Step>
                <Name>ExtractAccessSFDCAccessToken</Name>
            </Step>
            <Step>
                <Name>PopulateSFDCOAuthAccessToken</Name>
                <Condition>(scresponse.status.code = 200)
		and  (lookupcache.LookupSFDCAccessToken.cachehit = "false")
		</Condition>
            </Step>

@Dino @sudheendras @Anil Sagar @ Google I found you guy's response whenever its regarding lookup or populate cache issues. Can you please help me?

Can you try following.

1. Remove <Prefix/>from CacheKey in PopulateCache policy. According to document Prefix will override Scope - https://docs.apigee.com/api-platform/reference/policies/working-cachekeys.html#usingscopeandprefix . I can see prefix is not present in Lookup cache

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" name="PopulateSFDCOAuthAccessToken">
    <DisplayName>PopulateSFDCOAuthAccessToken</DisplayName>
    <Properties/>
    <CacheResource>SFDCAccessToken</CacheResource>
    <CacheKey>
        <KeyFragment ref="access_token"/>       
    </CacheKey>
    <Scope>Global</Scope>
    <!--<ExpirySettings>
        <TimeoutInSec>82800</TimeoutInSec>
    </ExpirySettings> -->
    <Source>sfdc_access_token</Source>
</PopulateCache>

2. If above is not working then add prefix in both PopulateCache and LookupCache.

Ex: <Prefix>myapplication</Prefix>

3. If cache functionality is used only in one proxy you can change Scope to Proxy.