Can response cache policy attached to conditional flow in API Proxy ?

Below is the use case,

I have an API proxy with 5 different resources of GET method. I would like to attache response cache policy to only on resource in same API proxy. Is it possible ?

Documentation says, Response cache policy can be attached only to preFlow & postFlow but not conditional flow. In that case i cannot implement above use case. Is it a doc error ? Or above use case is not possible ?

Solved Solved
0 21 1,941
1 ACCEPTED SOLUTION

Hi @Anil Sagar - I have definitely implemented ResponseCache policy in conditional flow before. It works 100%. I guess the docs need updated.

cc @Floyd Jones

View solution in original post

21 REPLIES 21

Hi @Anil Sagar - I have definitely implemented ResponseCache policy in conditional flow before. It works 100%. I guess the docs need updated.

cc @Floyd Jones

Thank you @Ozan Seymen for quick reply. Really helpful 🙂

@Ozan Seymen , From Edge UI It's not possible to add response cache policy to conditional flow. I have tried using API Bundle upload option. It doesn't work as expected. Exists with "[Error: Error uploading policy: 400]" error. I believe recent version of edge doesn't support it. Need more details from engineering.

Hi @Anil Sagar - good to know. Must be a UI thing (which I don't really use day to day). I have APIs in production that has this policy in conditional flows so it definitely works outside of UI.

Thank you @Ozan Seymen , Will follow up with Engineering and keep you updated..

@Ozan Seymen , Yes it works using XML. Earlier it was due to some other issue i got 400 error response. UI & Docs need to be fixed.

Thanks for the info on this, guys. We'll take care of this in the docs.

Awesome, Thank you @Floyd Jones 🙂 Keep us posted with updates.

there seems to be a problem with it being in MULTIPLE flows though.. so if you need to use response caching in more than one place, you are going to have a problem...

Not applicable

I could not find ResponseCache policy in Conditional flow,whereas in Preflow and Postflow I am able to see the Policy name in the list when I click +Step.

So,whether this will also be modified in free trial?

@RadR4 Yes, Exactly . That's the issue. I think it's a bug in Apigee Edge UI also along with docs. So, I was wondering it's supported or not. I think its an issue introduced in recent version of Edge UI update. We will notify our engineering team regarding this. Haven't verified whether this works from API Bundle. Need to check. But as per @Ozan Seymen seems like it's supported. Look alike good issue to find out root cause. We will keep you updated.

Just FYI, @RadhamaniRamadoss , It's not in particular with Free Trial. It's an issue with Apigee Edge, applies same for paid accounts too along with free.

Not applicable

Hi @Anil Sagar, In conditional flow we were supporting response cache policy. In conditional flow, we have to attach response cache policy to both request and response flow.

Sample conditional flow snippet:

<Flow name="CacheFlow"> <Description/> <Request> <Step> <Name>Response-Cache-1</Name> </Step> </Request> <Response> <Step> <Name>Response-Cache-1</Name> </Step> </Response> <Condition>(proxy.pathsuffix MatchesPath "/ip")</Condition> </Flow>

Thank you @tskumar@apigee.com , Yes It works using XML. UI need to be fixed & Docs needs to be updated. @docs FYI. Currently, UI doesn't allow you to add response cache policy using + Icon. See attached screenshot.

1105-screen-shot-2015-09-08-at-51200-pm.png

1106-screen-shot-2015-09-08-at-51211-pm.png

1107-response-cache.png

Cheers,

Anil Sagar

@tskumar@apigee.com , Any reason why we are not allowing more than one response cache policy in an API Proxy ?

@Anil Sagar When a response cache policy fetched the cached entry in request flow, it will jump to the response cache policy attachment point at Response flow. If there is more than 1 policy, it leads to confusion of choosing the jumping point.

@Benjamin Goldman , FYI , See above comment by @tskumar@apigee.com

Response Cache Policy acts like a point where response flow starts executing in the case of a cache hit. You might have a query like , "Why can't it be a starting point of response flow ?" Assume, there is a policy like XML -> JSON & then Cache Response , It goes to the starting point again which will lead to errors. So, We are using Response Cache policy in response flow as a point to start the response flow in case of cache hit. Hope it helps.

Is it not possible to execute policies on the request flow after a positive hit? Like logging policies or callouts?

Also: what if you only want to put response caching on your get methods, but not on your post methods (and you have say.. 100 of each..) does this not create an extremely limiting issue for the utility of caching in the first place?

Not applicable

@Anil Sagar -- I agree with Ben's comment/question. The fundamental issue is that if we want to execute response cache in, say, 2 of our 4 conditional flows, at this point we are not able to do so. If a conditional flow is started on the request side - it's mutually exclusive to any other conditional flow, and therefor there should be no confusion in what response flow to execute if cache is hit - it should be the response side of the same conditional flow. Therefor a user should be able to put the cache check and cache record on the request/response sides of the same conditional flow.

Per Apigee's definition of flows:


"Only one flow executes per transaction—the first flow whose condition evaluates to true.


In a conditional flow, the condition is evaluated in both the request and response. You cannot have separate conditions for request and response."

Conditional flows are mutually exclusive, and if cache is "hit" on a conditional flow which causes the flow to jump to the response side, the response side should be of the same conditional flow as of the one where cache was hit:

3042-cache-flow.png

The error reported by Apigee UI is a bug in the system:

3041-cache-error.png

The error says that cache is included twice - but including cache multiple times in mutually-exclusive flows is NOT including it twice. The system should be able to tell that only one of the policies will execute by virtue of being included in a "run only one" flow.

Your comments would be valid if you tried to include cache in pre-flow AND in conditional flows, but that's not what we are talking about. The way the system operates right now, we are severely limited in being able to create complex conditional flow proxies that would implement response caching

Thank You @Boris for your simple illustrated digram above.