Can cache write variable ?

I will explain my problem that's make my question.

I have a Cache in my Proxy Endpoint route. It works fine.

But I modify a validation that instead to be in a specifc route, we want to validate globaly.

So the validation compare the origin header and set true if we have the origin in our list and set false if not.

The problem , this validation when was set in a specific route, If I was looking for a Raise Fault GLOBALLY for other route, the variable was empty (not true, not false) because this variable was set in a specific route. It was working well.

Now I change this validation to be GLOBAL for all flow. The problem is the validation write FALSE !!!

So when I validate the value , it's FALSE not empty like previously, so I have an error.

The problem is the cache not enter in the Response, so when I validate the target.host it's empty because it's the cache who send the response.

So I was looking to know if it's possible to set my variable when cache is launched, that way I can set it to true when I use the cache.

Maybe not clear to understand my problem, but the question is clear: Can I set a variable when the cache is used?

Thanks

0 2 174
2 REPLIES 2

the question is clear: Can I set a variable when the cache is used?

I'm sorry I didn't understand all of the details of your situation, but as to your specific question.... there is a clear answer.

When retrieving from Cache (via LookupCache) you can check to see if the cache lookup was successful by examining the variable which was to receive the value. LookupCache is like this:

<LookupCache name='LC-1'>
    <CacheResource>cache1</CacheResource>
    <AssignTo>variable1</AssignTo> <!-- name of flow variable -->
    <Scope>Application</Scope>
    <CacheKey>
      <!--  <Prefix>apiAccessToken</Prefix> -->
      <KeyFragment ref='whatever' />
    </CacheKey>
</LookupCache>

And that says to populate a context variable named 'variable1' with the output of the lookup.

You can then use a Condition element to check the contents of that variable. If it is null, the lookup has failed.

To check to see if a Lookup attempt was made AT ALL, you would need a second policy Step. The flow might look like this:

<Step>   
   <Name>LookupCache-1</Name> <!-- may succeed, or may not succeed -->
</Step>
<Step>   
   <!-- set a variable here to indicate that the lookup was attempted  -->
   <Name>AssignMessage-1</Name> 
</Step>

And the Assignmessage would use AssignVariable to set a true/false .

<AssignMessage name='AM-1'>
  <AssignVariable>
    <Name>lookup_attempted</Name>
    <Value>true</Value>
  </AssignVariable>
</AssignMessage>

Since 2 weeks, I found another solution to my problem, doing something else. But for my question, you seem to answer correctly. Thanks