CouchbaseNetClient is expiring things way too quickly


My Coworker has exposed this issue.

The bug / fix is that the duration is placed in the milliseconds parameter of the TimeSpan constructor. This should be in the seconds parameter. This is highlighted in his notes, below.

This documentation tells you to use to specify expiration in seconds
If you want an item to live for less than 30 days, you can provide a TTL in seconds or as Unix time.

So when I specify my Expiry as 2592000 = 30 days my doc is expiring in 41 minutes.

Turns out they are asking users to specify seconds but using it as milliseconds -
var result = Upsert(document.Id, document.Content, document.Cas, document.Expiry.ToTtl());

            return ToTtl(new TimeSpan(0, 0, 0, 0, (int)duration));

Timespan -


@unhuman -

There is a discrepancy between the server documentation and the SDK documentation ( here too) regarding TTL. The SDK expects milliseconds to be passed in and it will handle the conversion specified in the server documentation to Unix time; this is for convenience. The reason the SDK uses milliseconds is because it’s a more standardized way of specifying a TTL than seconds from an API perspective.

Note that there are additional overloads (but none for Document), which take a TimeSpan as the TTL; for those methods it’s preferable over the overloads that take a unsigned int.

I opened up a ticket to address this here. Sorry for any confusion this may have caused.



Thanks for the explanation. We’ve worked around it here.

If we’re using milliseconds, however, wouldn’t a long be a better implementation than a uint? uint cuts off at 24 days.


Actually I believe uint is 49 days; agreed ulong would be better. The suggested work around is to use one of the overloads that takes a K/V pair and not a document and includes a TimeSpan for an expiry.

I created a ticket here to add a property to IDocument and/or change the Type to ulong: This would be a potentially breaking change, so it won’t likely be addressed until the next major release.