The operation has timed out (Get from cache)

Hi everyone,

I set up the cache with the current SDK 3.x, and it works great when I “Set” objects into it (I can see more than 200 operations/sec)
But when i want to “Get” objects from it, I have some “operation has timed out” issues.
I’ve read some other posts about it, and I confirm I have only one instance of my DistributedCache (DI).
I think the problem comes from my “use” of this cache : I use it in a batch process, and for a majority of my “Get” requests, the entry does not exists (I catch the DocumentNotFoundException). Since I have no other methods than Get and Set from IDistributedCache (I would love a CheckIfExists method :wink: ), I have to catch the DocumentNotFoundException.
Maybe this way of doing is bad, and can cause the “Operation Time out” on the others requests sent asynchronously.
Can you tell me if i’m wrong ? Is there a better way to check if the entry exists in the cache ?
Thanks.

1 Like

@david-77 its true there is no CheckIfExists method or TryGetAsync method, but probably you can write a wrapper method that first calls a ExistsAsync and then does a GetAsync as a work around maybe ?

It’s an implementation bug in the early work on the SDK 3 conversion of the cache provider. The provider should be catching that specific exception and returning null.

2 Likes

Hi @AV25242
Thanks but the “ExistsAsync” method does not exists (or any of that kind) in the IDistributedCache interface.
Maybe this method is available using the plain .Net CouchbaseClient ? But doing so, I would lose the IDistributedCache pattern.
@btburnett3, thanks again for the explanation. Not sure if I would prefer a “null” value instead of this exception, but I understand the goal of this.
Finally, I tried several config options to increase the timeout, and I made it work with the “KvTimeout” property :

  serviceCollection.AddCouchbase(opt => {
            opt
            //.WithConnectionString("http://192.168.1.xxx:8091")
            .WithConnectionString("couchbase://192.168.1.xxx")
            .WithCredentials(username: "MyDistributedCache", password: "xxxxxx")
            .KvTimeout = TimeSpan.FromSeconds(120); //Querytimeout and SearchTimeout has no effects on this issue
            opt.CircuitBreakerConfiguration.Enabled = false;             
            }
        ) ;
        serviceCollection.AddDistributedCouchbaseCache("MyDistributedCache", setup => setup.LifeSpan = TimeSpan.FromMinutes(600));

You can notice I set the circuit breaker to false. As I described before , I had a lot of DocumentNotFoundException which causes the activation of the circuit breaker.
Experiencing that, i wonder if the circuit breaker should be disabled by default when we use a bucket for cache ? Or do you think my way of using it is too specific ?

yeah @david-77 realized after I saw @btburnett3 messages.

IDistributedCache is a standard Microsoft interface, so we need to follow it’s spec, which is returning null for misses.

2 Likes

@btburnett3 again, thanks for the explanation :wink: