LookupCache Policy cannot find cache.

So I'm pretty sure my PopulateCache is working. As When I use the LookupCache in the request where I made the cache, I could see cache being populated on trace and on lookupcache, it assigns the cache it found to the proper variable. However, when I use the same lookupcache policy I used earlier on anothe proxy.

PS:

> My cache is not yet expired as i set it to 10 minutes, but when looking the value of the cache even before the 10 minutes expiry, lookupcache policy could still not find the cache.

> I already undeployed and reployed my code multiple times and clear the cache in the environment settings, but its still the same

This is my Populate Cache Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <PopulateCache name="PC-CodeChallenge">     <DisplayName>PC-CodeChallenge</DisplayName>
    <CacheKey>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>CodeChallenge</KeyFragment>
    </CacheKey>
    <CacheResource>pkceCache</CacheResource>
    <!--<Source>proxy.code_challenge</Source>-->
    <Source>request.queryparam.code_challenge</Source>
    <!--<Source>request.queryparam.client_id</Source>-->
    <ExpirySettings>
        <!-- Access tokens expire after 10 minutes -->
        <TimeoutInSec>600</TimeoutInSec>
    </ExpirySettings>
    <!--<CacheResource>code_challenge</CacheResource>-->
</PopulateCache> 

This is my LookupCache Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="LC-CodeChallenge">
    <DisplayName>LC-CodeChallenge</DisplayName>
    <CacheKey>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>CodeChallenge</KeyFragment>
    </CacheKey>
    <CacheResource>pkceCache</CacheResource>
    <AssignTo>code_challenge</AssignTo>
</LookupCache>

I also noticed that the action in my trace is always pause. (see screenshot attached).

All the while in my other proxy where this same policy work, its value is continue. What's seems to be the problem of why this is pausing then?.

Solved Solved
1 5 304
1 ACCEPTED SOLUTION

If you want to use cache across proxies then make use of the Scope tag in both policies.

 <Scope>Global</Scope>

Any other scope tag will also append the apiproxyname with the cache key and hence the cache cant be used on other proxies.

BTW you are using CacheResource so remove the <ExpirySettings> from Populate cache.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Cache-1">
    <DisplayName>Populate Cache-1</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>CodeChallenge</KeyFragment>
    </CacheKey>
    <CacheResource>pkceCache</CacheResource>
    <Scope>Global</Scope>
    <Source>request.queryparam.code_challenge</Source>
</PopulateCache>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="LC-CodeChallenge">
    <DisplayName>LC-CodeChallenge</DisplayName>
    <CacheKey>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>CodeChallenge</KeyFragment>
    </CacheKey>
    <CacheResource>pkceCache</CacheResource>
    <AssignTo>code_challenge</AssignTo>
    <Scope>Global</Scope>
</LookupCache>

View solution in original post

5 REPLIES 5

If you want to use cache across proxies then make use of the Scope tag in both policies.

 <Scope>Global</Scope>

Any other scope tag will also append the apiproxyname with the cache key and hence the cache cant be used on other proxies.

BTW you are using CacheResource so remove the <ExpirySettings> from Populate cache.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Cache-1">
    <DisplayName>Populate Cache-1</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>CodeChallenge</KeyFragment>
    </CacheKey>
    <CacheResource>pkceCache</CacheResource>
    <Scope>Global</Scope>
    <Source>request.queryparam.code_challenge</Source>
</PopulateCache>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="LC-CodeChallenge">
    <DisplayName>LC-CodeChallenge</DisplayName>
    <CacheKey>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>CodeChallenge</KeyFragment>
    </CacheKey>
    <CacheResource>pkceCache</CacheResource>
    <AssignTo>code_challenge</AssignTo>
    <Scope>Global</Scope>
</LookupCache>

Great,now working for me thanks. Turns out I was missing the scope then. I thought the CacheResource is the one that acts like a global cache. So that CacheResource is for handling cache expiration then?.

We use Cache Resource when you don't want to use the included shared cache.

It can be used to expiry time and as a Admin you can clear the cache with a single click or using management apis.

Okay. I'm stuck again. So I have the Global Scope now. But the values of the cache are not being assigned to the proper variables. See attached trace log here

It will only work if I added the same Lookup Policy in the flow again. My Lookup Policy is the ff. below.

<LookupCache name="LC-ChallengeMethod">
    <DisplayName>LC-ChallengeMethod</DisplayName>
    <CacheKey>
        <Scope>Global</Scope>
        <KeyFragment ref="request.queryparam.code_challenge"/>
        <KeyFragment>ChallengeMethod</KeyFragment>
    </CacheKey>
    <AssignTo>challenge_method</AssignTo>
    <CacheResource>pkceCache</CacheResource>

</LookupCache>

Ah nevermind. It turns out its actually working and has always been working like before. However, the Trace log just doesn't show the variables being read and assigned. Odd, been debugging this for hours, only to find out its actually doing what's it supposed to do.

I already read from the documentation that this sometimes happens if I have a <Prefix> in my cachekey, but deleting that still didn't show the variables in the tracelog making me think my Lookup Cache policy is not working. Oh well, there goes another time wasted by relying to much on the trace log.