Flow variable for lookup cache policy which tells the elapsed time of the cached entry

Not applicable

There is a need for my proxy to know how long a cached entry was put into Cache by Populate cache policy. Is there flow variable available after executing lookup Cachce to find the elapsed time when a cahce hit occurs?.

0 8 538
8 REPLIES 8

Hi @murali boyapati I do not recall any flow variable on top of my head which stores what you are looking for.

But I think you can build the functionality :

When you construct the cache key ... append a current timestamp as well. So your Populate Cache policy should have one of the key fragments as follows :

<KeyFragment ref="keyFrag1"/>

<KeyFragment ref="KeyFrag2"/>

<KeyFragment ref="system.timestamp"/>

Put that as the last key fragment.

When you do the key lookup do like this :

<CacheKey> 

<Prefix/> 

<KeyFragmentref="KeyFrag1"/>

<KeyFragmentref="KeyFrag2"/> 

</CacheKey>

So basically do not do the lookup based on the timestamp keyfragment.

Once retrieved , check the timestamp against the lookupcache.{policy-name}.cachekey flow variable using javascript or python policy.

I havn't tried this out yet, but I think this should work. Let me know what you find out.

Directly using the system.timestamp will give a class cast exception for not being able to cast from long to string. To avoid that I added a javascript policy just before the populate Cache policy:

context.setVariable("current_sys_time_in_string",context.getVariable("system.timestamp").toString());

And then in the populate lookup cache policy use "current_sys_time_in_string" .

Thanks

Sarthak

@sarthak I will try this and update on the result soon.

@sarthak Tried by adding <KeyFragment ref="system.time"/> as system.timestamp is giving cast exception as it is Long. But lookup cache policy is allays failing to hit the cache as the keys doesn't match now. do I need to specify anything on the lookup cache policy to look for only partial match of the key?

Yes I see the error. I updated the answer with the solution

I tried this and same issue as the Lookup key is not matching, it never identifying the cached object. So my policy is always returning cache hit as "false".

Yes you are right. You can do deletion of caches in a cascading manner but probably not a select. I am checking a few things and I will update if I find a viable solution.

@murali boyapati After thinking about it more I don't think the above approach will work. It might be possible to store the cache key and them current timestamp in a KVM map . And then use the KVM policy to check for the time just before the caching policy is executed.

Let me know what do you think about that approach ?

Not applicable

Instead of KVM I implemented using another populate cache policy to just store the timestamp and whenever a cache hit on the main cachekey I will look for cached timestamp using timestamp cachekey.