ContainerProperties.DefaultTimeToLive Property

Definition

Gets or sets the default time to live in seconds for item in a container from the Azure Cosmos service.

[Newtonsoft.Json.JsonProperty(NullValueHandling=Newtonsoft.Json.NullValueHandling.Ignore, PropertyName="defaultTtl")]
public int? DefaultTimeToLive { get; set; }
[<Newtonsoft.Json.JsonProperty(NullValueHandling=Newtonsoft.Json.NullValueHandling.Ignore, PropertyName="defaultTtl")>]
member this.DefaultTimeToLive : Nullable<int> with get, set
Public Property DefaultTimeToLive As Nullable(Of Integer)

Property Value

It is an optional property.

The unit of measurement is seconds. The maximum allowed value is 2147483647. A valid value must be either a nonzero positive integer, '-1' or null.

By default, DefaultTimeToLive is set to null meaning the time to live is turned off for the container.

Attributes
Newtonsoft.Json.JsonPropertyAttribute

Examples

The example below disables time-to-live on a container.

container.DefaultTimeToLive = null;

The example below enables time-to-live on a container. By default, all the items never expire.

container.DefaultTimeToLive = -1;

The example below enables time-to-live on a container. By default, the item will expire after 1000 seconds since its last write time.

container.DefaultTimeToLive = 1000;

Remarks

The DefaultTimeToLive will be applied to all the items in the container as the default time-to-live policy. The individual item could override the default time-to-live policy by setting its time to live.

When the DefaultTimeToLive is null, the time-to-live will be turned off for the container. It means all the items will never expire. The individual item's time to live will be disregarded.

When the DefaultTimeToLive is '-1', the time-to-live will be turned on for the container. By default, all the items will never expire. The individual item could be given a specific time-to-live value by setting its time to live. The item's time to live will be honored, and the expired items will be deleted in background.

When the DefaultTimeToLive is a nonzero positive integer, the time-to-live will be turned on for the container. And a default time-to-live in seconds will be applied to all the items. A item will be expired after the specified DefaultTimeToLive value in seconds since its last write time.

Applies to