putIfAbsent method

  1. @override
Uint8List putIfAbsent(
  1. Uint8List key,
  2. Uint8List value
)
override

Add a key, value pair to the underlying store if not key is in the underlying store. Returns the old value if key existed, otherwise value is returned.

putIfAbsent(utf8.encode('foo',utf8.encode('bar')
putIfAbsent(utf8.encode('foo',utf8.encode('baz') // returns 'bar'
get(utf8.encode('foo'); // returns 'bar'

Implementation

@override
Uint8List putIfAbsent(Uint8List key, Uint8List value) {
  var record = _recordPool.put(key, value, false) as RecordBlock;
  if (record.isNew) {
    _header.numBytes += record.size;
    _header.numRecords += 1;
  } else {
    _header.numBytes += record.value.length - value.length;
  }
  if (_flush) flush();
  return record.value;
}