TTL in seconds not working while creating document object in Couchbase

java

#1

Hi,

Using SDK 2.4.3, we tried to set a ttl in a JSON Document of couchbase. We tried with 1minute (60 sec).Below sample code -
JsonDocument jdoc = JsonDocument.create (“XYZ”,60,content);
JsonDocument cbNotification = bucket.upsert(jdoc);

I came to know that rather than directly removing doc from CouchBase on expiry of TTL, CB waits for getting searched again, which will trigger the deletion upon expiration. I tried multiple time and checked but its not happening. Am I missing something?
Please help and thanks in advance.


#2

do you mean you get the document after 60 seconds and it still there?


#3

yes…That’s right. I try to view it and it’s still there after one minute.


#4

Do you mean Couchbase Views? TTL defined for Key/Value operations. You should use GET operation to check if it still there.


#5

@tanban1990 don’t try to view it on the UI, rather perform a kv get operation and see if it returns null. It should be at least, since we got a couple of test cases in our integration test suite and they pass :slight_smile:


#6

Gotch the problem.but need solution from you guys…:slight_smile:
I am creating entry in couchbase with upsert i.e
JsonDocument jDocs = JsonDocument.create(“key”,ttl,value)
bucket.upsert(jDocs);
And again via a separate flow i am using upsert again with same TTL value to update the entry.

As I found out this --“the 2nd upsert resets the TTL - and the document will never expire.”, Is my analysis proper?Is this the reason my entries are not getting expired?Will the second upsert reset the TTL even though we provide TTL value explicitly?If yes, then how to restore the TTL value rather than resetting it with 2nd upsert?

Thanks,
Tanmoy