Couchbase - java 2.1.1 SDK. When I read a document over time to live, the expiration is always zero

The code below demonstrates the problem. I insert a document with ttl in 2 seconds. If I read it immediately, the value will be returned. If I read it in a few seconds, it will be empty - the document has already expired.

HOWEVER - in both cases, the "expire" field of the document metadata returns zero. Any idea why?

int expiry = 2;
JsonObject val = JsonObject.empty().put("somekey", "just some value");            


JsonDocument newDoc = JsonDocument.create("ttl.test", expiry,val);
JsonDocument retVal = bucket.insert(newDoc);

JsonDocument readDoc = bucket.get("ttl.test");

if(readDoc == null){
       System.out.println("1. null");
} else {
       System.out.println("1. not null: " + readDoc.expiry());
}

// Wait for slightly more than the TTL
try {
       Thread.sleep(2500);
} catch (InterruptedException e) {
       e.printStackTrace();
}

readDoc = bucket.get("ttl.test");
if(readDoc == null){
       System.out.println("2. null");
} else {
       System.out.println("2. not null: " + readDoc.expiry());
}

Conclusion:

  • not null: 0
  • Null

Therefore - TTL works fine, however the expiration is always zero in the JsonDocument that I am reading from the server;

+4
source share
1 answer

, , Memcached (. ), get, .

+3

All Articles