I need to set the Expiry as configurable; which can be either in minutes / days.
But while creating a document, if I give as below, its taking it Expiry as 10 days.
TimeSpan ts = new TimeSpan(0, 10, 0);
var contentDoc = new Document<string>
{
Id = docId,
Content = content,
Expiry = Convert.ToUInt32(ts.Minutes)
};
So how can we set minutes as Expiry time for document.
TimeSpan has static methods to assist with building values, for example:
var expiry = TimeSpan.FromMinutes(10);
var expiry = TimeSpan.FromHours(1);
var expiry = TimeSpan.FromSeconds(100);
The reason why your code is not working as expected is when assigning the value from the timespan to the expiry value, you need to use the TotalSeconds property as unit. We have provided an extension method to assist with getting that value, example below:
var expiry = TimeSpan.FromMinutes(10);
var contentDoc = new Document<string>
{
Id = docId,
Content = content,
Expiry = expiry.ToTtl();
};
Expiry property does not work correct in the couchbase-net-client if I set seconds value there.
It works correct if I set milliseconds. But it`s not possible to use any timestamp in that way. When I convert any timestamp to milliseconds (multiply by 1000) there is uint overfrlow and value is changed to unexpected value.
So only one option is available for now is to set short TTL. E.g. value for 1 day TTL will be 86400000 milliseconds. Developers are better to change type of Expiry to ulong.
As a workaround I used method override with TimaSpan.
_bucket.UpsertAsync(GetDocId(doc), doc, TimeSpan.FromDays(90));