consuldotnet
consuldotnet copied to clipboard
Does support Agent Caching?
In this documentation, there is cached parameter. but I don't see this parameter in QueryOptions
, is caching currently supported?
Hi, indeed it is not supported currently but should be easy enough to add. Would you like to contribute a PR?
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, 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
.
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?
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)