Populate cache not executing when kept in preflow request path

Not applicable

mycachetest-rev2-2016-04-03.zipI have kept Populate Cache in preflow request path.Once I clear the cache ,I dont see it executing.But if I keep the populate cache policy in preflow response path,its executing.

Please let me know why its is behaving so.

I have attached my proxy bundle for reference.

Solved Solved
0 8 170
1 ACCEPTED SOLUTION

Not applicable

@arghya das @Prithpal Bhogill @Dino

Finally I got what is the issue.

<GenerateResponse/> in OAuth2 GenerateAccesstoken policy was causing the issue.It didnt allow any of the policies to execute following it.I even confirmed by creating an AssignMessage policy after OAuthv2 policy and it didnt execute.I removed the tag and now PopulateCache is working fine in preflow itself.

Ya..I got that my usecase is weird to use clientid for caching accesstoken.But I am just doing a poc to understand PopulateCache..So,I feel its fine.

View solution in original post

8 REPLIES 8

Can you elaborate more on the problem you are seeing. Keep in mind that none of us can see what you are doing. The only information we have is what you write here.

You wrote "once I clear the cache, I don't see it executing." That doesn't provide any clarity to me. I don't know what you're seeing, what specific actions you are taking (for example, which curl commands you invoke...), what results you expect to see, and what results you actually see.

People are better able to help if you very clearly explain the situation and the problem you're confronting.

@Dino

Sorry about that..I will give clear explanation.

Former Community Member
Not applicable

Hi @RK4 it appears from your proxy that you are trying to look up the cache & populate the "TestVariable" in the pre-flow/request before you even populate the cache. In which case if you place the lookup step in the pre-flow / response prior to the "Assign Message" policy, the "TestVariable" will be loaded & the response set with the value you expect.

Are you actually trying to cache an access token or using that as an example? As you may be aware access tokens are automatically generated (OAuth2 --> GenerateAccessToken) & cached in our data store & accessed by certain policies (OAuth2 --> VerifyAccessToken). Its also a little unclear what exactly you are trying to do here? Maybe help us understand your use case a little better.

@Prithpal Bhogill ,

I read that we can cache any entity using Populatecache policy.And thatswhy I tried to cache OAuth accesstoken generated from OAuth2 policy.

I tried to do this similar to "OutboundOauthsample" proxy in APIGEE samples.

I first have lookup cache and tried to lookup for cache value.If its not there ,only then I am trying to execute OAuthaccesstoken and Populatecache.

And I also have a condition in OAuthaccesstoken and populatecache as below,

<Condition>lookupcache.Lookup-Cache-1.cachehit == "false"</Condition>

With this condition its executing OAuth policy but not populatecache when all are kept in Request preflow.

But if Populate cache is kept in Response Preflow,its executing.

adas
New Member

@RK4 The scenario you are trying to implement is a little unrealistic because of two reasons:

1. You are trying to cache a POST call which is actually going to generate the access token

2. You are using the client_id as the cache key for caching the token.

Both sound a little weird to be honest. If you want to explore how lookup, populate and invalidate cache policies work and how you can take advantage of them, here's an example you can try. I am attaching the sample bundle here.apigee-discovery.zip

You would call this using the following curl call:

Fetch Cached Response
curl -v "http://{org}-{env}.apigee.net/apigee-discovery" -H "username: {username}" -H "password: {password}"

Cache Refresh (Bypass Lookup and Invalidate Cache)
curl -v "http://{org}-{env}.apigee.net/apigee-discovery" -H "username: {username}" -H "password: {password}" -H "cache.refresh: true"

The username and password would be your org admin credentials. You would need to create an organization level keyvaluemap caled mapURL as below:

POST /v1/o/{org}/keyvaluemaps

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<KeyValueMap name="mapURL">
    <Entry name="mgmtHost">api.enterprise.apigee.com</Entry>
</KeyValueMap>

This example demonstrates the use of various cache policy patterns through a service callout scenario. The service callout response is cached using the populatecache policy and then the same response is looked up using the lookupcache policy. If the cache.refresh header is set to true, the lookup cache is skipped and the cache is invalidated, so that the service callout is forced in the flow and it fetches fresh data from the backend. I hope this explains the caching policies and usage pattern for you.

Thankyou @arghya das .I will check this.

Not applicable

@arghya das @Prithpal Bhogill @Dino

Finally I got what is the issue.

<GenerateResponse/> in OAuth2 GenerateAccesstoken policy was causing the issue.It didnt allow any of the policies to execute following it.I even confirmed by creating an AssignMessage policy after OAuthv2 policy and it didnt execute.I removed the tag and now PopulateCache is working fine in preflow itself.

Ya..I got that my usecase is weird to use clientid for caching accesstoken.But I am just doing a poc to understand PopulateCache..So,I feel its fine.

@RK4 , Thank you for the update. I have seen similar issues when I was learning Apigee Edge. Trace tool is really helpful to resolve above kind of errors. Many times it takes longer to troubleshoot above errors & it's time taking without trace tool. Trace tool should be used as primary troubleshooting tool.