Skip to content

Time to Live (TTL)

Items can have a time-to-live (TTL), also known as an expiration time. After expiration time passes, the item will be automatically deleted from the system. TTLs can be configured via the ttl attribute of an Item type definition. A TTL may be a specific timestamp field of an Item or can be calculated relative to another field or metadata property of an Item. It is important to note that a TTL value is only guaranteed to be respected to the nearest second, and that a zero value in a field used in the TTL calculation disables the TTL. The examples below demonstrate this in more detail:

An Item with a TTL that expires a constant two hours after its creation:

1
export const MyType = itemType("MyType", {
2
keyPath: "/mytype-:id",
3
ttl: {
4
source: "fromCreated",
5
durationSeconds: 2*60*60,
6
},
7
fields: {
8
id: { type: uint, fieldNum: 1 }
9
}
10
})

An Item with a TTL that expires a constant two days after its latest modification:

1
export const MyType = itemType("MyType", {
2
keyPath: "/mytype-:id",
3
ttl: {
4
source: "fromLastModified",
5
durationSeconds: 2*24*60*60,
6
},
7
fields: {
8
id: { type: uint, fieldNum: 1 }
9
}
10
})

An Item with a TTL that expires an arbitrary duration (supplied in the ttlDebounceDuration field) from its latest modification.

1
export const MyType = itemType("MyType", {
2
keyPath: "/mytype-:id",
3
ttl: {
4
source: "fromLastModified",
5
field: "ttlDebounceDuration",
6
},
7
fields: {
8
id: {type: uint, fieldNum: 1},
9
ttlDebounceDuration: {type: durationMilliseconds, fieldNum: 2}
10
}
11
})

An Item with an exact (but arbitrary) timestamp TTL.

1
export const MyType = itemType("MyType", {
2
keyPath: "/mytype-:id",
3
ttl: {
4
source: "atTimestamp",
5
field: "ttlTimestamp",
6
},
7
fields: {
8
id: {type: uint, fieldNum: 1},
9
ttlTimestamp: {type: timestampMicroseconds, fieldNum: 2}
10
}
11
})