Response Cache policy for conditional flows

Question:

I am using response cache in conditional flow to cache data from a backend resource, reducing the number of requests to the resource.

I have 4 conditional flow and added in both request & response step as below.

<?xml version="1.0" encoding="UTF-8"?>
<Flow name="1">
   <Description />
   <Request>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Request>
   <Response>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Response>
   <Condition>(proxy.pathsuffix MatchesPath "/1")</Condition>
</Flow>
<?xml version="1.0" encoding="UTF-8"?>
<Flow name="2">
   <Description />
   <Request>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Request>
   <Response>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Response>
   <Condition>(proxy.pathsuffix MatchesPath "/2")</Condition>
</Flow>
<?xml version="1.0" encoding="UTF-8"?>
<Flow name="3">
   <Description />
   <Request>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Request>
   <Response>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Response>
   <Condition>(proxy.pathsuffix MatchesPath "/3")</Condition>
</Flow>
<?xml version="1.0" encoding="UTF-8"?>
<Flow name="4">
   <Description />
   <Request>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Request>
   <Response>
      <Step>
         <Name>Response-Cache-1</Name>
      </Step>
   </Response>
   <Condition>(proxy.pathsuffix MatchesPath "/4")</Condition>
</Flow>

==

<?xml version="1.0" encoding="UTF-8"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="Response-Cache-1">
   <DisplayName>Response-Cache-1</DisplayName>
   <FaultRules />
   <Properties />
   <CacheKey>
      <Prefix />
      <KeyFragment ref="request.uri" type="string" />
   </CacheKey>
   <Scope>Exclusive</Scope>
   <ExpirySettings>
      <ExpiryDate />
      <TimeOfDay />
      <TimeoutInSec ref="">300</TimeoutInSec>
   </ExpirySettings>
   <SkipCacheLookup />
   <SkipCachePopulation />
</ResponseCache>

==

What I was expecting:

##################

Cache the data from backend resource for each conditional flow & respond from cache( for subsequent requests).

What I am facing:

###############

See below error.

Response cache step definition Response-Cache-1 can not be attached more than once in the response path

We are using on-prem 4.15.04.

Tried few options to apply the policy in proxy pre/ & target post flow but see same error.

Let me know your suggestions if any one used response cache with conditional flows?

-Vinay

1 9 1,227
9 REPLIES 9

Former Community Member
Not applicable

Hi @vinay poreddy looks like from your XML fragment that you want to cache the response when either of the 4 flows occur. If that is the case could you not have 4 conditions in one flow? This could work unless you are doing other things in those flows that are different from each other. Another alternative is use Populate / Lookup Cache policies for more explicit control.

@vinay poreddy , Just FYI, Moving forward while posting any code, use code widget in text editor & format xml code using tools like http://www.freeformatter.com/xml-formatter.html . That will help to improve readability & visibility. Thank you 🙂 I have done same for now.

@vinay poreddy , Great Question & Thank you for asking same. I never know about this design restriction & your question helped me to learn about same.

It's by design, see the documentation here that explains same in error codes section.

2598-screen-shot-2016-04-29-at-102456-am.png

So, Please change your flow condition to match that / use step condition in preflow / postflow instead of flow conditions. Do you know you can conditionally execute policies using step conditions ? Step conditions is the easy way to solve your issue.

@docs , Can we also add this information in policy description "Where" section to avoid confusion ? Right now, it's only visible in error codes section. Thank you 🙂

I tested using Proxy Endpoint Response flow and it took care of any target endpoint it hit.

I have other issues which made a decision to remove the caching policy but good to explore response caching policy.

@vinay poreddy , Glad to know that. If above answer resolved your query, please click on accept link below the answer so that it will be helpful for other users too. Thank you.

this is a great work around, but it does make me wonder: are caching and conditional flows mutually exclusive?

maybe this should be logged as a bug?

@Benjamin Goldman , I don't see any reason why we cannot add multiple response cache policies in conditional flows until unless i am missing something that i don't know.

Yes, As you said, Looks like a bug for me. Ideally, It should override other caches if added multiple times. I have raised a bug in Jira - MGMT-3395 .

Hi @Anil Sagar, Any luck with this issue? We have a use case to implement response caching limited to only some condition flows. I'm unable to attach ResponseCache policy to multiple conditional flows. Thanks in advance 🙂

@vinay poreddy

Can you please try the below solution?

1) I am assuming that you are also having one condition for unknown resource i.e. if path suffix does not matches /1, /2, /3. /4

2) Use the cache policy in the PROXY POSTFLOW and add the KEYFRAGMENT with proxy path suffix

This will resolve the issue. Please let me know if this method is incorrect