Purge the cache by partial key

Hi Team,

I have requirement to purge the cache by partial key.

Creating the cache key in ResponseCache as per below code:

<CacheKey>
<Prefix>products</Prefix>
<KeyFragment ref="productId" type="string"/>
<KeyFragment ref="request.querystring" type="string"/>
</CacheKey>

Here we are caching with productId and it's url.

But want to purge all products which are having same product Id.(query String may be different).

and using following code to purge the cache in invalidateCache but it purged all the keys. Please suggest how can we do this?

<CacheKey>
<Prefix>products</Prefix>
<KeyFragment ref="productId" type="string"/>
</CacheKey>
0 5 371
5 REPLIES 5

@Nikhil Verma,

You can use PurgeChildEntries set to true, in addition to the product id as the cachekey in Invalidate cache policy.

@Nagashree B Thanks for reply ,

Used following code but it's cleared all the entries from cache.not specific to product id.

 <CacheKey>
        <Prefix>products</Prefix>
        <KeyFragment ref="productId" type="string"/>
    </CacheKey>
    <PurgeChildEntries>true</PurgeChildEntries>

Can you please post your complete xml for the invalidate cache policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvalidateCache async="false" continueOnError="false" enabled="true" name="EV_Invalidate_product">
    <DisplayName>EV_Invalidate_product</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix>products</Prefix>
        <KeyFragment ref="productId" type="string"/>
    </CacheKey>
    <CacheResource>CacheResource</CacheResource>
    <CacheContext>
        <APIProxyName/>
        <ProxyName>default</ProxyName>
        <TargetName>default</TargetName>
    </CacheContext>
    <PurgeChildEntries>true</PurgeChildEntries>
</InvalidateCache>

I can reproduce your issue when using a keyfragment of request.querystring in the caching policy. The "=" character from the query string becomes part of the cache key, and when using invalidate cache it seems to cause this entry is to get invalidated always.

As a workaround, please use a keyfragment that's not querystring / without "=" character. If there's a particular query parameter you're using, you could reference that value directly?