Issue with Key Fragment in Cache Key of Populate cache & lookup cache

ref in keyfragment is not working for me. I'm trying to cache jwt based on id & role. Below code snippet is not taking dynamic values
 
I am adding my code with some truncated details...
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache continueOnError="false" enabled="true" name="PC-XXXX>
 
<CacheResource>JWT</CacheResource>
<Source>generated_jwt</Source>
<Scope>Exclusive</Scope>
<CacheKey>
<KeyFragment ref="Id"/>
<KeyFragment ref="role" />
</CacheKey>
<ExpirySettings>
<TimeoutInSec>3600</TimeoutInSec>
</ExpirySettings>
</PopulateCache>
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache continueOnError="false" enabled="true" name="LC-XXXXX">
<DisplayName>LC-XXXXX</DisplayName>
<CacheResource>JWT</CacheResource>
<AssignTo>generated_jwt</AssignTo>
<Scope>Exclusive</Scope>
<CacheKey>
<KeyFragment ref="Id"/>
<KeyFragment ref="role" />
</CacheKey>
</LookupCache>
 
Solved Solved
2 4 122
1 ACCEPTED SOLUTION

 


@priyanka212 wrote:

I have 123456789 as ID & "Admin, Viewer" as one of the value of role. Do you think this value is not accepted as cache key? Can this be the problem


 

possibly.  If this is the problem , base64-encoding the role before using it as a cache key, would solve that.

View solution in original post

4 REPLIES 4

Below code snippet is not taking dynamic values

1. It looks like your PopulateCache and LookupCache step configurations are both referring to a composite key, and both have fragments that refer to context variables named Id and role, and in the same order. That's good.  Those things are required if you want to get the same resulting cache key.  Next question: Are you certain those context variables contain values, at the time the policies execute? And are those values the same, at both times?

2. You have used "Exclusive" as the cache Scope value. According to the policy documentation, this means that if the policy is attached to the ProxyEndpoint flow, prefix is of the form ApiProxyName_ProxyEndpointName. Whereas if the policy is attached at TargetEndpoint, prefix is of the form ApiProxyName_TargetName. So if you have different attachment points, you may not get the same resulting cache key. Or, if these policies are in different API proxies, you will not get the same cache key. Different cache keys means you will not be able to retrieve a value via the LookupCache policy, that you inserted with the PopulateCache policy. (I believe if the proxyendpoint and the targetendpoint have the same names, then even if the Lookup and Populate policies are attached in different endpoints, coincidentally you will get the same cache key.) 

A separate note - the JWT id (aka jti) is defined to be unique. If the ID in your policy configuration refers to the JWT ID (aka jti), then it will be unique.  Which may mean, depending on your approach, there is no need to use both id AND role as the cache key. If the ID does not refer to the jti, then... ignore this comment!~  

ID is not JWT ... JWT value is kept in source variable if you see in code

<Source>generated_jwt</Source>

I have 123456789 as ID & "Admin, Viewer" as one of the value of role. Do you think this value is not accepted as cache key? Can this be the problem

 


@priyanka212 wrote:

I have 123456789 as ID & "Admin, Viewer" as one of the value of role. Do you think this value is not accepted as cache key? Can this be the problem


 

possibly.  If this is the problem , base64-encoding the role before using it as a cache key, would solve that.

I had an issue with JavaScript code. Fixed it