maximumSize property

int get maximumSize

Retrieves the current maximum cache size.

Implementation

int get maximumSize => _maximumSize;
set maximumSize (int value)

Changes the maximum cache size.

If the new size is smaller than the current number of elements, the extraneous elements are evicted immediately. Setting this to zero and then returning it to its original value will therefore immediately clear the cache.

Implementation

set maximumSize(int value) {
  assert(value >= 0);
  if (value == _maximumSize) return;

  _maximumSize = value;

  // Clear cache if the maximum size is set to zero.
  if (_maximumSize == 0) {
    clear();
  } else {
    while (_cache.length > _maximumSize) {
      _cache.remove(_cache.keys.first);
    }
  }
}