consuldotnet icon indicating copy to clipboard operation
consuldotnet copied to clipboard

Does support Agent Caching?

Open weilence opened this issue 2 years ago • 1 comments

In this documentation, there is cached parameter. but I don't see this parameter in QueryOptions, is caching currently supported?

weilence avatar Apr 29 '22 05:04 weilence

Hi, indeed it is not supported currently but should be easy enough to add. Would you like to contribute a PR?

mfkl avatar Apr 29 '22 08:04 mfkl

Hi, Is there any important hint about using agent caching? I am using your awesome library and I want to use the caching mechanism. therefore I have docker-hosted Consul on my PC environment to develop my code. and I am sending my query using this code:

var result = await _client.KV.Get(key,new QueryOptions
       {
           UseCache = true,
           MaxAge = TimeSpan.FromMinutes(1),
       });

So receiving the old value is expected until one minute after updating the value in consul admin. but I am receiving the updated value immediately. can you help me or teach me about the caching concept if I got it wrong?

shokri-navid avatar Nov 25 '23 13:11 shokri-navid

Hi, Is there any important hint about using agent caching? I am using your awesome library and I want to use the caching mechanism. therefore I have docker-hosted Consul on my PC environment to develop my code. and I am sending my query using this code:

var result = await _client.KV.Get(key,new QueryOptions
       {
           UseCache = true,
           MaxAge = TimeSpan.FromMinutes(1),
       });

So receiving the old value is expected until one minute after updating the value in consul admin. but I am receiving the updated value immediately. can you help me or teach me about the caching concept if I got it wrong?

Hi @shokri-navid,

I think you expectation that it is going to serve old values for a minutes is incorrect. With your example you can expect that is going to return data from cache for at most one minute (not at least one minute). BTW, you can check whether the result comes from cache by checking the XCache field in the result (QueryResult). The XCache field should be set and be either hit or miss.

marcin-krystianc avatar Nov 27 '23 08:11 marcin-krystianc

It was my mistake to choose the correct word, and yes I should expect that value should be cached for at most 1 minute. But when I change the value from the Consul panel for example change "Hello" ===> "BYE!!!". and then I call the _client.KV.Get Immediately, the result is updated and I am faced with "BYE!!!". can Consul update the agent cache? is there any duplex connectivity between the Consul and its Agents?

shokri-navid avatar Nov 27 '23 12:11 shokri-navid

I don't know exactly how your test environment looks like so I don't know whether the immediate value update is expected or not. In my opinion the best way to check whether the result comes from cache is to check the XCache field in the result (see example in https://github.com/G-Research/consuldotnet/blob/master/Consul.Test/AgentTest.cs#L412-L435)

marcin-krystianc avatar Nov 27 '23 21:11 marcin-krystianc