PurgeChildEntries in InvalidateCache Policy

In invalidateCache policy there is an element called "PurgeChildEntries" which promises to purge all cache entries which shares the same Prefix ...... does this work ?

My Response cache policy looks like this :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="Response-Cache">
    <DisplayName>Response Cache</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix>sarthak_lm</Prefix>
        <KeyFragment ref="cityName" type="string"/>
    </CacheKey>
    <ExpirySettings>
        <ExpiryDate/>
        <TimeOfDay/>
        <TimeoutInSec ref="">600</TimeoutInSec>
    </ExpirySettings>
    <CacheResource>abcd</CacheResource>
</ResponseCache>

And my Invalidate Cache policy looks like this :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvalidateCache async="false" continueOnError="false" enabled="true" name="Invalidate-Cache">
    <DisplayName>Invalidate Cache</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix>sarthak_lm</Prefix>
    </CacheKey>
    <CacheResource>abcd</CacheResource>
    <PurgeChildEntries>true</PurgeChildEntries>
</InvalidateCache>

So I basically want to purge/delete all cache entries which has a prefix of sarthak_lm. This is not happening.

I have two APIs : http://amer-demo14-test.apigee.net/v1/weather/dover - Response Cache lies on the PreFlow of this call.

http://amer-demo14-test.apigee.net/v1/invalidate-cache : This is the second call which just have the invalidate cache policy attached to it.

Both policies are in the same proxy. Any suggestions ?

0 16 1,065
16 REPLIES 16

Not applicable

Indeed this functionality does work as you explain it with the following caveats:

  1. This policy will invalidate everything below the provided CacheKey fragment you provide - meaning it can empty your entire cache with a single call. Test it well.
  2. Deleting a large number of entries may have negative impact on overall performance and availability in production. Use with caution and be aware of this potential impact.
  3. Purge child entries works only with a cacheKey fragment - not with a prefix. There is no way to remove all entries from a prefix that I am aware of.

As to your specific scenario - I would suggest verifying that you are in the environment with both calls, and that the invalidate policy is indeed being executed as expected without any errors. As a second step you might try removing the prefix. The latest implementation I have experience with was NOT using a prefix value, it is possible that their is an issue when a prefix is supplied.

Thanks @David Allen ... I have tried those things already .. not much difference...

InvalidateCache works perfectly when I specify my cache Key specifically :

<CacheKey>
        <Prefix>sarthak_lm</Prefix>
        <KeyFragment ref="cityName" type="string"/>
    </CacheKey>

But as soon as I make PurgeChildEntries true and remove the CacheKey it stops working. Might be I am missing something ? Do you have a working sample ?

Hi @sarthak , I remember seeing purge working with prefix .

Is your cache distributed ? both policies running on the same env ? private cloud or cloud ?

BTW Purge true + no prefix will delete the whole cache .

not distributed.

cloud

both in same proxy - so yes, same env,org.

purge + no prefix ... yes i expect something like that to happen ... but nothing happening so far .... stupid mistake maybe ? you have a sample ?

Not applicable

To be clear, and perhaps I missed this in the original question - purge child entries works only with a cacheKey fragment - not with a prefix.

If you move your prefix to a static initial element in your cacheKey you will see the behavior you expect.

My apologies for not including that in my original answer. I will edit it now.

@David Allen @Maruti Chand

Sorry I created a few confusions.

If you go to http://apigee.com/docs/api-services/reference/invalidate-cache-policy to the "PurgeChildEntries" section you will see it says "true to purge cache entries that share the prefix value set by the <Prefix> element configured for this policy" . It that tells me if I set PurgeChildEntries to true then I will be able to delete all entries that have the common same Prefix.

Am I understanding this completely wrong ? Or this is a bug ? If bug is it a doc bug or a product bug?

@sarthak, I've updated the docs to reflect David's answer, swapping <KeyFragment> for <Prefix>. Let me know if what you see there now doesn't reflect current behavior.

http://apigee.com/docs/api-services/reference/invalidate-cache-policy#PurgeChildEntriesElement

Thanks!

Steve

adas
New Member

@sarthak The PurgeChildEntries does work, but you need to set the KeyFragment in order for this to work correctly. If you don't set the KeyFragment, then it might purge all cache entries. It doesn't consider the values specified in Prefix when matching the KeyFragment. Can you test and let me know, your observations based on the above points.

Purge Child Entries does work. But not with Cache Prefix. Only works with KeyFragments. The doc has been recently modified due to this thread. Previously it stated that PurgeChildEntries will work even if only Prefix is specified. That was the source of the confusion.

@sarthak Ah, I see. Yes it was always meant for KeyFragment and not the Cache Prefix. Its good that we finally have the doc reflecting the correct behaviour.

I basically want to purge/delete all cache entries which has a prefix of sarthak_lm

Came across this old thread and wanted to mention a management api call that invalidates cached items with prefix: http://docs.apigee.com/management/apis/post/organizations/%7Borg_name%7D/environments/%7Benv_name%7D...

Can you please tell how can i pass prefix?

Use keyfragments, you can then use purge child trees with the first keyfragment for example.

Tried but not working .

I am using following key to cahce the data

<CacheKey>

        <Prefix>products</Prefix>

        <KeyFragment ref=“id” type="string"/>

        <KeyFragment ref="request.querystring" type="string"/>

    </CacheKey>

and want to remove all products which are having same id.Using below mention key in InvalidateCache.But it's not working. Please sugget how can i do this?

<CacheKey>

        <Prefix>products</Prefix>

        <KeyFragment ref=“id” type="string"/>

    </CacheKey>

Hi @nikhilverma, were you able to solve your problem above? I am facing the same problem.

for a different topic I found out purgeChildEntries true work, I definetly dont need to remove all the other caches, so I have it as false.