Skip to content

Support for Instant in doc.getExpiration() for Long-Term Expiry #2006

Open
@Divya-1200

Description

@Divya-1200

I noticed that in the buildUpsertOptions and
buildInsertOptions methods, the doc.getExpiration() value is always converted to seconds using Duration.ofSeconds().

else if (doc.getExpiration() != 0) {
    options.expiry(Duration.ofSeconds(doc.getExpiration()));
}

While options.expiry() can accept both Duration and Instant, converting the expiration exclusively to seconds can lead to limitations, especially for setting expirations greater than 50 years. This is because Couchbase supports durations up to 50 years when expressed as seconds, but longer durations must be provided as an Instant.

Suggestion

if (doc.getExpiration() > MAX_SECONDS_EXPIRATION) {  
    options.expiry(Instant.ofEpochSecond(doc.getExpiration()));  
} else {  
    options.expiry(Duration.ofSeconds(doc.getExpiration()));  
}

Does this approach align with the intended design of the buildUpsertOptions and buildInsertOptions methods, or are there other considerations that necessitate the current implementation?

Looking forward to your feedback and insights!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions