Shared Cache extend expiration time.

Hi, my business requirement says to refresh the expiration of the cache everytime I read it. for N minutes.

For test purposes, I created using populate cache and expiration time for 3 minutes.

I have an api that read the same cache using lookupCache. and immediately after populate the same cache with same key and another 3 minutes expiration time.

I check the cachehit property that tells me the cache is alive.

1. First minute --> I see it working. cachehit is true and I see the data

2. 2nd minute --> I see it working. cachehit is true and I see the data.

3. 3rd minute --> I see it working. cachehit is true and I see the data.

4. 4th minute ---> X fails. cachehit is false and cache data is lost

I was expecting that everytime i did the looulp the cache expiration time was bumped another 3 minutes.

if this is not working through PopulateCache, what is the best way to extend expiration time of shared cache ?

Solved Solved
0 4 186
1 ACCEPTED SOLUTION

A (not eficcient) way to do it would be to use an InvalidateCache policy after the lookup and before the PopulateCache

View solution in original post

4 REPLIES 4

A (not eficcient) way to do it would be to use an InvalidateCache policy after the lookup and before the PopulateCache

Hi @deboraelkin , Im doing the invalidate cache + populate, and repeated the test.

Im still seing no data in the 4th minute test. (even though the previous 3 runs, should have bumped the expiration time 3 more minutes)

is it possible my invalidate logic is wrong ?

This is my invalidate policy and my populate cache run immediately after. Im paying attention to have same scope, and to do purge child entries true. (but even with false failed my scenario)

<InvalidateCache async="false" continueOnError="false" enabled="true" name="Invalidate-Cache-1">
    <DisplayName>Invalidate Cache-1</DisplayName>
    <Properties/>
    <CacheKey>
        <Prefix>pocUserSession.</Prefix>
        <KeyFragment ref="someIdHere"/>
    </CacheKey>
    <Scope>Global</Scope>
    
    <PurgeChildEntries>true</PurgeChildEntries>
</InvalidateCache>
<br>
<PopulateCache async="false" continueOnError="false" enabled="true" name="Populate-Cache-1">
    <DisplayName>PopulateSession</DisplayName>
    <Properties/>
    
    <CacheKey>
        <Prefix>pocUserSession.</Prefix>
        <KeyFragment ref="someIdHere"/>
    </CacheKey>
    <Scope>Global</Scope>
    <ExpirySettings>
        <TimeoutInSec>180</TimeoutInSec>
        
    </ExpirySettings>
    <Source>sessionData</Source>
</PopulateCache>
<br>

Not sure this is the cause, but try removing the "." in the CacheKey prefix.

Also, try and do a trace and see what the final cache key looks like both in populate and invalidate policies

Hi!, It seems my policy started to work, so ill accept your first answer.

the problem I think it was the purge child true, I changed it to false and I was able to extend the cache 6-7 times then waited 4 minutes and saw the expected cache dissapear.

I will still monitor this as I continue with my poc. thank you