push method

void push(
  1. Memory memory
)

Pushes a memory into the buffer.

If at capacity the oldest item is displaced (circular queue).

Implementation

void push(Memory memory) {
  _pruneExpired();

  if (_queue.length >= capacity) {
    final displaced = _queue.removeFirst();
    _logger.debug(
        'WM displaced: "${_trunc(displaced.memory.content)}"');
  }

  _queue.addLast(_WorkingSlot(
    memory: memory,
    enteredAt: DateTime.now(),
  ));

  _logger.debug(
      'WM push: "${_trunc(memory.content)}" '
      '(size: ${_queue.length}/$capacity)');
}