Counters and POCO

Hi,

Counters are great. they are atomic and you don’t need to read before write !

But what do you do if your POCO is having some counters as members ? It basically renders all their benefits useless :hushed:

Reading counters using additional gets also hinders performance and creates wait state where one get should be enough.

What is the best practice for using counters in .Net ?

Itay

@itay -

There isn’t a great story at the moment for counters within JSON documents ATM, but this will likely change in the future when the server implements sub-document commands. For now the best practice for .NET would be to use Increment/Decrement on a key.

Reading counters using additional gets also hinders performance and creates wait state where one get should be enough.

I am not am not aware of a performance issue, but internally the value stored with Increment/Decrement value is the ascii representation of the value and not the binary 64bit integer. So if you were to use Get to retrieve a value then you’ll have to use a string Type parameter, for example:

var result = bucket.Get<string>("the-counter-key");

Instead of a ulong, which is the intuitive thing to do.

-Jeff

Thanks,

I mean that in addition to the document Get, one should also get each counter separately (perhaps in parallel or even after reading the doc).