Cache JWT and don't re-generate JWT if the claims content already was processed

Lookup cache & populate cache has cache keys, did not see reference of lookup using content of JWT for Apigee-X

Is there any ways to avoid regeneration of JWT  when payload data of JWT already exists in cache because it was already created in past, with required custom payload, hence should not regenerate JWT but get the same JWT from cache which same name and branch 

Eg: If i create JWT with  required custom payload data like say name and branch as an example (was created in past ) and when I get request to  regenerate the same JWT, with same name and branch (residing in payload as custom data), which was generated in past then JWT should not be regenerated but should get same JWT it from cache ?

Fully understand limits of apigee cache, but the question is on getting the JWT from cache based on payload data.

eg:

Header(

"typ" : "JWT"

alg: XX-555"

}

PAYLOAD (

sub:"my subject@subject.com"

name: xxxname

branch:xxxbranch

exp:4444

.....

}

 

@dino 

Solved Solved
3 1 107
1 ACCEPTED SOLUTION

Assuming "name" and "branch" are the only payload claims that vary across different JWT, then you should be able to use a composite key referencing  those values, in your PopulateCache + LookupCache to cache the JWT. 

The LookupCache will look something like: 

 

<LookupCache name='LC-JWT'>
    <AssignTo>flowvariable</AssignTo> <!-- name of flow variable -->
    <Scope>Global</Scope>
    <CacheKey>
      <Prefix>jwt</Prefix>
      <KeyFragment ref='variable-holding-name' />
      <KeyFragment ref='variable-holding-branch' />
    </CacheKey>
</LookupCache>

 

 and the PopulateCache will be like this: 

 

<PopulateCache name='PC-JWT'>
    <Source>variable.containing.generated-jwt</Source>
    <Scope>Global</Scope>
    <CacheKey>
      <Prefix>jwt</Prefix>
      <KeyFragment ref='variable-holding-name' />
      <KeyFragment ref='variable-holding-branch' />
    </CacheKey>
    <ExpirySettings>
      <TimeoutInSeconds>3500</TimeoutInSeconds> <!-- lifetime of jwt, less some margin -->
    </ExpirySettings>
</PopulateCache>

 

 

View solution in original post

1 REPLY 1

Assuming "name" and "branch" are the only payload claims that vary across different JWT, then you should be able to use a composite key referencing  those values, in your PopulateCache + LookupCache to cache the JWT. 

The LookupCache will look something like: 

 

<LookupCache name='LC-JWT'>
    <AssignTo>flowvariable</AssignTo> <!-- name of flow variable -->
    <Scope>Global</Scope>
    <CacheKey>
      <Prefix>jwt</Prefix>
      <KeyFragment ref='variable-holding-name' />
      <KeyFragment ref='variable-holding-branch' />
    </CacheKey>
</LookupCache>

 

 and the PopulateCache will be like this: 

 

<PopulateCache name='PC-JWT'>
    <Source>variable.containing.generated-jwt</Source>
    <Scope>Global</Scope>
    <CacheKey>
      <Prefix>jwt</Prefix>
      <KeyFragment ref='variable-holding-name' />
      <KeyFragment ref='variable-holding-branch' />
    </CacheKey>
    <ExpirySettings>
      <TimeoutInSeconds>3500</TimeoutInSeconds> <!-- lifetime of jwt, less some margin -->
    </ExpirySettings>
</PopulateCache>