We are having below aerospike set connfiguration and want that entry from the Map should be auto deleted after 'x' days. How should the same be achieved using Spring data aerospike ?
@Document(collection = "cust")
public class Customer {
@Id
@Field(value = "PK")
private String custId;
@Field(value = "mobileNumber")
private String mobileNumber;
@Field(value = "creationTime")
private String creationTime;
@Field(value = "corrDetails")
private HashMap<String, Object> corrDetails;
}
Moreover there are around 10 - 12 <K,V> pairs in my map with each having different structure, and I want only 1 Particular <K,V> to expire after x days !!
Dependencies looks like :-
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-data-aerospike</artifactId>
<version>${aerospike.data.version}</version>
<scope>system</scope>
<systemPath>${basedir}/lib/spring-data-aerospike-2.0.0.RELEASE.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
</dependency>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-helper-java</artifactId>
<version>1.2.2</version>
</dependency>
There is no native feature/ability within Aerospike server to assign a TTL to a K:V pair in a map data type. You will have to build it from the application. i.e. store the desired expiration timestamp when you insert the K:V pair, with the K:V data, and then periodically scan the entire database to remove expired KV pairs or remove expired K:V pairs on reads (less intensive but carries expired K:V pairs until read) - no elegant option really. Perhaps revisit the data model.
Aerospike does have the ability to expire and remove entire records i.e. assign TTL to an entire record - and then it has an internal thread to do the expiration and removal for you. So if you can store this K:V pair that you want to keep for x days as a separate record, then that is straightforward. But anything at bin level or at bin data level (like map data type), you have to handle from the application.