Look up and Populate cache is not working

Not applicable

Hi, i have implemented Look up cache populate cache to store oauth token. I have added a conditional flow like

<Step> <Condition>lookupcache.oauth-token-lookup-cache.cachehit == "false"</Condition> <Name>CallOauthToGetToken</Name> </Step>

When the next request comes, the cachehit will always be false and every request the populate cache is called and getOauthToken is called.

Please find the look up cache and populate cache below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <LookupCache async="false" continueOnError="false" enabled="true" name="oauth-token-lookup-cache"> <CacheResource>oauth-token-cache</CacheResource> <AssignTo>request.header.Authorization</AssignTo> <Scope>Exclusive</Scope> <CacheKey> <KeyFragment>apiAccessToken</KeyFragment> <KeyFragment ref="request.header.Authorization"/> </CacheKey> </LookupCache>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <PopulateCache async="false" continueOnError="false" enabled="true" name="oauth-token-populate-cache"> <CacheResource>oauth-token-cache</CacheResource> <Source>request.header.Authorization</Source> <Scope>Exclusive</Scope> <CacheKey> <KeyFragment>apiAccessToken</KeyFragment> <KeyFragment ref="request.header.Authorization"/> </CacheKey> <ExpirySettings> <TimeoutInSec>600</TimeoutInSec> </ExpirySettings> </PopulateCache>

Could you please let me know where am i doing wrong.

0 2 1,071
2 REPLIES 2

@Hemanth

A couple of things:

1) Exclusive cache scope includes the ProxyEndpoint or TargetEndpoint name in the cache key, so you should always be doing your lookup and populate in the same proxy or target. The cache key for both policies ends up being something like this:

{org}__{env}__{proxyname}__{proxyendpoint/targetendpoint name}__apiAccessToken__Bearer {token}

There's nothing inherently wrong with that -- just want to point it out

2) You store the cache key ("Bearer {token}") as the cache value, so on lookup you'd overwrite the Authorization header with the Authorization header on a cachehit. This seems a bit strange to me, but your cachehit variable should be fine.

3) The variable name "lookupcache.oauth-token-lookup-cache.cachehit" is a boolean value -- I think it is more appropriate to have your condition be lookupcache.oauth-token-lookup-cache.cachehit == false (without quotation marks), although it looks like Edge will accept the string as a match for the boolean variable.

4) Your timeout is 10 minutes, so obviously you'd get a cache miss after 10 minutes.

In testing in my own org with the same exact policies, I cannot reproduce your problems. I wrote a quick proxy to test this (not best practice, just thrown together) -- I can send it to you if you send me an email -- my email is

mdunker AT apigee.com (replace AT with at sign).

Hi @Mike Dunker can you please send me the proxy at dreams4krishanu AT gmail.com