Classdesc

TTLUtil is a utility class that may be used to create and manage TimeToLive objects and convert between TTL and record expiration time. TTL behavior and relation to record expiration time is described in TimeToLive. Note that on input durations, TTL objects and expiration times are validated for correctness and NoSQLArgumentError is thrown if the representation is invalid.

See

TimeToLive

Hierarchy

  • TTLUtil

Properties

DO_NOT_EXPIRE: TimeToLive

Convenience constant to indicate that the row should not expire. It can be passed as TTL to a put operation to remove expiration from existing row.

MILLIS_IN_DAY: number

Convenience constant representing number of milliseconds in 1 day.

MILLIS_IN_HOUR: number

Convenience constant representing number of milliseconds in 1 hour.

Methods

  • Constructs TTL from absolute expiration time given reference time from which to measure record expration. TTL is computed as follows. First, expirationTime is rounded up to the nearest hour boundary. If inHours argument is specified, then the returned TTL will be in hours or days depending on whether inHours is true or false. If inHours is not specified, we check if the adjusted expiration time indicates midnight in UTC time zone, in which case the retured TTL will be in days, otherwise it will be in hours. Then, the duration is computed as the difference between the adjusted expiration time and the reference time rounded up to the nearest hour or day (depending on which is used in the returned TTL as described above) and TTL with that duration is returned. Note that if expiration time is before or equal to the reference time, it is possible that the returned value will contain 0 or negative duration, which indicates that the record has already expired.

    Returns

    TTL object

    Throws

    if expirationTime or referenceTime is invalid

    Parameters

    • expirationTime: number | Date

      Expiration time represented as Date or number of milliseconds since Unix epoch

    • referenceTime: number | Date

      Reference time represented as Date or number of milliseconds since Unix epoch

    • Optional inHours: boolean

      Whether to return TTL in hours or days. If not specified, the unit of hours or days is determined as described above

    Returns TimeToLive

  • Creates TTL with duration of days

    Returns

    TTL object

    Throws

    if 'days' parameter is invalid

    Parameters

    • days: number

      Number of days as positive integer or Infinity

    Returns TimeToLive

  • Creates TTL with duration of hours

    Returns

    TTL object

    Throws

    if 'hours' parameter is invalid

    Parameters

    • hours: number

      Number of hours as positive integer or Infinity

    Returns TimeToLive

  • Returns the number of days in the TTL. If the TTL is specified in hours, the resulting days value is rounded down, which will result in 0 if TTL.hours < 24.

    Returns

    Number of days in the TTL object or Infinity

    Throws

    if TTL object is invalid

    Parameters

    Returns number

  • Converts TTL to absolute expration time given the reference time from which to measure the expiration. The semantics follows the rounding behavior described in TimeToLive so that the returned value will be rounded up to the nearest hour or day boundary.

    Returns

    Expiration time as Date instance, may be invalid if ttl represents no expiration (Infinity)

    Throws

    if TTL object or referenceTime is invalid

    Parameters

    • ttl: TimeToLive

      TTL object

    • referenceTime: number | Date

      Reference time represented as Date or number of milliseconds since Unix epoch

    Returns Date

  • Converts TTL to absolute expiration time in milliseconds since Unix epoch (January 1, 1970, 00:00:00 UTC). This method is the same as toExpirationTime returning time in milliseconds instead of as Date object.

    Returns

    Expiration time in milliseconds since Unix epoch or Infinity

    Throws

    if TTL object or referenceTime is invalid

    See

    toExpirationTime

    Parameters

    • ttl: TimeToLive

      TTL object

    • referenceTime: number | Date

      Reference time represented as Date or number of milliseconds since Unix epoch

    Returns number

  • Returns the number of hours in the TTL. If the TTL is specified in days, the return value is TTL.days * 24.

    Returns

    Number of hours in the TTL object or Infinity

    Throws

    if TTL object is invalid

    Parameters

    Returns number

  • Returns number of milliseconds in the TTL. This is equivalent to toHours multiplied by MILLIS_IN_HOUR.

    Returns

    Number of milliseconds in the TTL object or Infinity

    Throws

    if TTL object is invalid

    See

    toHours

    Parameters

    Returns number

Generated using TypeDoc