Search code examples
spring-data-couchbase

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>

Solution

  • 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,