Lookup Cache policy doesn't always retrieve the value

Not applicable

Hello everybody,

I am using a Populate Cache Policy to store a JSON object in Cache. This seems to work good.

When I try to retrieve it with a LookupCache policy, only one in two calls returns a value (same request).

Here are my 2 policies:

Populate Cache Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Cache">
    <DisplayName>Populate Cache</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment>mykey</KeyFragment>
    </CacheKey>
    <CacheResource>MyFirstCacheResource</CacheResource>
    <Scope>Exclusive</Scope>
    <ExpirySettings>
        <TimeoutInSec>172800</TimeoutInSec>
    </ExpirySettings>
    <Source>MyJSONObjectVariable</Source>
</PopulateCache>

LookupCache Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Cache">
    <DisplayName>Lookup Cache</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment>mykey</KeyFragment>
    </CacheKey>
    <CacheResource>MyFirstCacheResource</CacheResource>
    <Scope>Exclusive</Scope>
    <AssignTo>MyJSONVariable</AssignTo>
</LookupCache>

In the trace tool, for the same query:

CALL 1 :

3632-ok.png

CALL 2:

3634-ko.png

Recap:

3635-problem.png

Does anyone have any idea about this problem?

Thanks

0 10 630
10 REPLIES 10

HI @nsghir -

Welcome to the community !!!

Can you please include the CacheResource in your Lookup policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="Lookup-Cache">
    <DisplayName>Lookup Cache</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment>mykey</KeyFragment>
    </CacheKey>
    <CacheResource>MyFirstCacheResource</CacheResource>
    <Scope>Exclusive</Scope>
    <AssignTo>MyJSONVariable</AssignTo>
</LookupCache>

You need to leave CacheResource only if you are using the included shared Cache. More details here

Let me know if that works

Thank you 🙂

It was a copy/past error int the post, I have modified the post.

I'm using the same CacheResource

What is the <br> there ?

Also have you defined the Cache Resource in Env configurations ? In your case, the name will be "MyFirstCacheResource"

Like in the screenshot

3636-screen-shot-2016-09-30-at-105812-am.png

sorry I was using the html editor.

No worries - By adding the CacheResource, did it work ?

Unfortunately no.

Same problem

Hi @nsghir - Is it possible for you to share the API proxy bundle here ? I can take a look at it and get back to you

@Nader Sghir , Are you populating cache in one proxy & retrieveing cache in another proxy ?

@Nader Sghir , Looks like you are actually storing string "[object Object]", I don't think cache supports directly storing objects. Please convert json to string using stringify & the store same in cache. Can you please try that ? Find more info in this post here. Keep us posted.

@Anil Sagar

I've tried to store the JSON as string, I have got the same problem.

I am using the same API proxy to populate and retrieve cache. But different proxy endpoint:

Post to store
Get to retrieve