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());
}
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:
Therefore - TTL works fine, however the expiration is always zero in the JsonDocument that I am reading from the server;
source
share