how to use same lookup cacahe policy to read different cache resources

I have a requirement where I am getting cache resource name as a header and I need to lookup that cacheresouce. But when I try to use a variable in CacaheResource , It is not getting deployed. I am getting following error - "Invalid cache resource reference {private.jwks-cache} in Step definition Lookup-okta-token-Cache"

can you please help.

<LookupCache  name="Lookup-okta-token-Cache">
  <DisplayName>Lookup okta token Cache</DisplayName>
  <Properties/>
  <CacheKey>
    <Prefix>nordjwks</Prefix>
    <KeyFragment>1</KeyFragment>
  </CacheKey>
  <CacheResource>{private.jwks-cache}</CacheResource>
  <Scope>Application</Scope>
  <AssignTo>cached.nord.jwks</AssignTo>
</LookupCache>
Solved Solved
1 1 326
1 ACCEPTED SOLUTION

Nope, you can't do that.

You may not need to use a "dynamic" cache resource name. In fact it looks like you are trying to use the cache resource as a cache key, and that's not right.

What if .... instead of using multiple cache resources, you use the thing that "header" value as one part of the composite cache key?

Example

<LookupCache name="Lookup-okta-token-Cache">
  <DisplayName>Lookup okta token Cache</DisplayName>
  <CacheKey>
    <Prefix>nordjwks</Prefix>
    <!-- you can have as many key fragments as you like -->
    <KeyFragment ref='private.jwks-cache'/>
    <KeyFragment>1</KeyFragment>
  </CacheKey>
  <CacheResource>fixedCacheResource</CacheResource>
  <Scope>Application</Scope>
  <AssignTo>cached.nord.jwks</AssignTo>
</LookupCache>

This is the purpose of the cache key.

You will have to modify the corresponding PopulateCache policy as well.

View solution in original post

1 REPLY 1

Nope, you can't do that.

You may not need to use a "dynamic" cache resource name. In fact it looks like you are trying to use the cache resource as a cache key, and that's not right.

What if .... instead of using multiple cache resources, you use the thing that "header" value as one part of the composite cache key?

Example

<LookupCache name="Lookup-okta-token-Cache">
  <DisplayName>Lookup okta token Cache</DisplayName>
  <CacheKey>
    <Prefix>nordjwks</Prefix>
    <!-- you can have as many key fragments as you like -->
    <KeyFragment ref='private.jwks-cache'/>
    <KeyFragment>1</KeyFragment>
  </CacheKey>
  <CacheResource>fixedCacheResource</CacheResource>
  <Scope>Application</Scope>
  <AssignTo>cached.nord.jwks</AssignTo>
</LookupCache>

This is the purpose of the cache key.

You will have to modify the corresponding PopulateCache policy as well.