Ethan Shen
Ethan Shen

Reputation: 13

Spring-Data Couchbase - How to set TTL to document from property file

I am trying to set a TTL for document, I've learned that by putting @Document(expiry = x sec) works. But is there a way to read the value from a property file?

Here's my dependency:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath />
    </parent>
...
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-couchbase</artifactId>
    </dependency>

Upvotes: 1

Views: 528

Answers (2)

Deepak Naik
Deepak Naik

Reputation: 53

You can use expiryExpression to get the value from properties. Tested in spring-data-couchbase:4.3.1

@Document(expiryExpression = "${document.expiry}" , expiryUnit =TimeUnit.DAYS)

Upvotes: 0

deniswsrosa
deniswsrosa

Reputation: 2460

Unfortunately, this is not a feature yet. If you need a flexible TTL definition, you can use the touch method after the document is saved: https://docs.couchbase.com/sdk-api/couchbase-java-client-2.0.0/com/couchbase/client/java/Bucket.html#touch(java.lang.String,%20int)

Additionally, you could also use the standard save method.

Best,

Upvotes: 1

Related Questions