validateTTL static method
Accepts a string which represents the MillisecondsSinceEpoch
Returns ttlMs
which is time_to_live in MilliSecondsSinceEpoch
Method ensures ttl
has a valid value
Implementation
static int validateTTL(String? ttl) {
int ttlMs = 0;
if (ttl == null || ttl.trim().isEmpty) {
return ttlMs;
}
try {
ttlMs = int.parse(ttl);
} on FormatException {
throw InvalidSyntaxException(
'Valid value for TTL should be greater than or equal to 0');
}
// TTL cannot have a negative value.
if (ttlMs < 0) {
throw InvalidSyntaxException(
'Valid value for TTL should be greater than or equal to 0');
}
return ttlMs;
}