Invalidate Cache policy doesn't work

Hi, I'm trying to clear a cache entry after read it. I can populate and lookup cache correctly but the InvalidateCache Policy doesn't work following the same schema and in the debug session there is not any variables that specify the cache key used by it (as the LookupCache Policy has), I'm using the following configuration
PopulateCache (working):

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PopulateCache async="false" continueOnError="false" enabled="true" name="PC-StoreLogErrorRequest">
    <DisplayName>PC-StoreLogErrorRequest</DisplayName>
    <Properties/>
    <CacheKey>
        <KeyFragment ref="apigee.cacheId"/>
    </CacheKey>
    <Scope>Application</Scope>
    <ExpirySettings>
        <TimeoutInSeconds>30</TimeoutInSeconds>
    </ExpirySettings>
    <Source>cacheVar</Source>
</PopulateCache>

 

LookupCache (working):

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LookupCache async="false" continueOnError="false" enabled="true" name="LC-GetLogErrorRequest">
    <DisplayName>LC-GetLogErrorRequest</DisplayName>
    <Properties/>
    <Scope>Application</Scope>
    <AssignTo>requestLogError</AssignTo>
    <CacheKey>
        <KeyFragment ref="apigee.cacheId"/>
    </CacheKey>
</LookupCache>

 

InvalidateCache (not working):

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvalidateCache async="false" continueOnError="false" enabled="true" name="IC-InvalidateLogErrorRequest">
    <DisplayName>IC-InvalidateLogErrorRequest</DisplayName>
    <Properties/>
    <Scope>Application</Scope>
    <CacheKey>
        <KeyFragment ref="apigee.cacheId"/>
    </CacheKey>
</InvalidateCache>

 

In order to test, I'm executing the LookupCache policy after the InvalidateCache Policy but I still have a cachehit. I want to know how can I Invalidate the cache and suggest to add debug variables like the other policies have

Thank You in advance

Solved Solved
0 3 633
1 ACCEPTED SOLUTION

I'm sorry to hear you're having trouble. 

In my experience, the Cache policies work pretty reliably. It's possible you are experiencing a "race condition", especially if you are using Apigee Edge. Apigee Edge uses a 2-layer cache and propagation of cache events happens "lazily".  After invalidation, An immediate read of the cache from a different server might return the previously cached (stale) data.  But if you wait long enough, the cache entry should be invalidated. How long is "long enough"?  I don't know, maybe 2 seconds? 

In Apigee X  or hybrid, this should not be a problem as cache propagation is cleaned up a bit. 

Please see this screencast for a demonstration of the caching policies in Apigee X.  

And please find attached the working example proxy that I used in that demonstration. 

 

View solution in original post

3 REPLIES 3

I'm sorry to hear you're having trouble. 

In my experience, the Cache policies work pretty reliably. It's possible you are experiencing a "race condition", especially if you are using Apigee Edge. Apigee Edge uses a 2-layer cache and propagation of cache events happens "lazily".  After invalidation, An immediate read of the cache from a different server might return the previously cached (stale) data.  But if you wait long enough, the cache entry should be invalidated. How long is "long enough"?  I don't know, maybe 2 seconds? 

In Apigee X  or hybrid, this should not be a problem as cache propagation is cleaned up a bit. 

Please see this screencast for a demonstration of the caching policies in Apigee X.  

And please find attached the working example proxy that I used in that demonstration. 

 

Hi Dino, thank you so much by your answer, I added a 3 seconds Java Delay (also written by you) https://github.com/DinoChiesa/Apigee-Java-Delay  in the middle of the policies and it works fine now (I'm using Apigee X by the way)

Edsasto_2-1655930730106.png

 

 

 

 

GREAT! Thanks for the feedback.