timetolive property

int get timetolive

Implementation

int get timetolive => S.toInt(_timetolive) ?? 0;
set timetolive (dynamic ttl)

Implementation

set timetolive(dynamic ttl) {
  _timetolive = 0;
  if (ttl == null) return;

  int factor = 1;
  if (ttl is String)
  {
    ttl = ttl.trim().toLowerCase();
    if (ttl.endsWith('s')) factor = 1000;
    if (ttl.endsWith('m')) factor = 1000 * 60;
    if (ttl.endsWith('h')) factor = 1000 * 60 * 60;
    if (ttl.endsWith('d')) factor = 1000 * 60 * 60 * 24;
    if (factor > 1) ttl = (ttl.length > 1) ? ttl.substring(0, ttl.length - 1) : null;
  }

  if (S.isNumber(ttl))
  {
    int t = S.toInt(ttl)! * factor;
    if (t >= 0) _timetolive = t;
  }
}