lookup cache is not working for subsequent requests

I am new to APIGEE. I am trying to implement and a populate cache and lookup cache usecase.

From my test, I am not able to populate cache and lookup cache in subsequent request. However just for testing if I lookup cache within the same request I get a successful hit. So my setup is

Lookup cache --> service callout --> populate cache --> lookup cache

The first lookup cache is always false and the second lookup cache is true for every request. My expectation is the first lookup cache should return a cache hit after the first request.

Can you please provide me guidance on what could be wrong.

First lookup

lookupcache.Lookup-Cache-1.cachekey vouchers__9344401449022lookupcache.Lookup-Cache-1.cachehit falselookupcache.Lookup-Cache-1.failed falselookupcache.Lookup-Cache-1.cachename woolworths__test__edr_customer_cachelookupcache.Lookup-Cache-1.assignto voucherjson

Second Lookup

lookupcache.Lookup-Cache-2.cachename woolworths__test__edr_customer_cachelookupcache.Lookup-Cache-2.assignto flowvarlookupcache.Lookup-Cache-2.cachekey vouchers__9344401449022lookupcache.Lookup-Cache-2.failed falselookupcache.Lookup-Cache-2.cachehit true

both lookup cache policy

    <CacheKey>
        <Prefix>vouchers</Prefix>
        <KeyFragment ref="edrno"/>
    </CacheKey>
     <CacheResource>edr_customer_cache</CacheResource>
    <Scope>Global</Scope>

EDIT

On further testing, I found that once in a while I get a valid cache hit on the first lookup. Approximately only 2 in 10 requests return "true" for cache hit. Does this mean something is wrong with the environment?


Here is the full configuration for the policies.

Thanks for helping out.

Lookup cache 1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Cache-1">
    <DisplayName>Lookup Cache 1</DisplayName>
    <FaultRules/>
    <Properties/>
    <CacheKey>
        <Prefix>vouchers</Prefix>
        <KeyFragment ref="edrno"/>
    </CacheKey>
     <CacheResource>edr_customer_cache</CacheResource>
    <Scope>Global</Scope>
    <AssignTo>voucherjson</AssignTo>
</LookupCache>

Lookup cache 2

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Cache-2">
    <DisplayName>Lookup Cache 2</DisplayName>
    <FaultRules/>
    <Properties/>
    <CacheKey>
        <Prefix>vouchers</Prefix>
        <KeyFragment ref="edrno"/>
    </CacheKey>
     <CacheResource>edr_customer_cache</CacheResource>
    <Scope>Global</Scope>
    <AssignTo>flowvar</AssignTo>
</LookupCache>

Flow

        <Flow name="getvouchers">
            <Description/>
            <Request>
                <Step>
                    <FaultRules/>
                    <Name>Extract-edrno</Name>
                </Step>
                <Step>
                    <FaultRules/>
                    <Name>Lookup-Cache-1</Name>
                </Step>
                <Step>
                    <FaultRules/>
                    <Name>call-IDM</Name>
                </Step>
                <Step>
                    <FaultRules/>
                    <Name>Voucher-XML-to-JSON</Name>
                </Step>
                <Step>
                    <FaultRules/>
                    <Name>Populate-Cache-1</Name>
                </Step>
                <Step>
                    <FaultRules/>
                    <Name>Lookup-Cache-2</Name>
                </Step>
            </Request>
            <Response>
                <Step>
                    <FaultRules/>
                    <Name>Assign-Message-2</Name>
                </Step>
            </Response>
            <Condition>(proxy.pathsuffix MatchesPath "/getvouchers/{edrno}") and (request.verb = "GET")</Condition>
        </Flow>
Solved Solved
0 8 1,602
1 ACCEPTED SOLUTION

It was something to do with environment. Once I undeployed the code and redeployed it, things started working fine.

Golden rule of computing 🙂

Thanks.

View solution in original post

8 REPLIES 8

Hi @SPatil,

I notice that your cachekey in the first lookup is "vouchers_ 9344401449022", with a leading space for the edrno field. The second lookup cachekey is "vouchers_9344401449022", with no space. Could that be your issue?

Mike

I think its the formatting when I pasted the code.

I rechecked both the cache keys. They are exactly the same

vouchers__9344401449022

I dont believe that is the problem.

There was a glimmer of hope 🙂

Can you post the full XML for Lookup-Cache-1 and Lookup-Cache-2?

It was something to do with environment. Once I undeployed the code and redeployed it, things started working fine.

Golden rule of computing 🙂

Thanks.

Glad it's working!

Having exactly the same problem. However redeployment didn't help. 😞

Same problem for me also. How to solve it??

Do you have an extract policy? If you have, try <Source clearPayload="false">

When clearpayload="true", i was getting data from cache on every subsequent calls.

My flow is - Lookup->ServiceCallOut->PopulateCache->AssignMessage->ExtractVariables

Have conditions which will do servicecallout and populatecache when lookupcache is empty.

Assignmessage when cache has data and then extract data for further processing.