put method

void put(
  1. String key,
  2. List<int> bytes,
  3. Map<String, String> headers, {
  4. required int status,
  5. int? generation,
})

Implementation

void put(
  String key,
  List<int> bytes,
  Map<String, String> headers, {
  required int status,
  int? generation,
}) {
  _refresh();
  if (generation != null && generation != _generation) return;
  if (status != 200 ||
      headers.keys.any((k) => k.toLowerCase() == 'set-cookie') ||
      bytes.length > maxBytes ||
      maxEntries <= 0) {
    return;
  }
  final previous = _pages.remove(key);
  if (previous != null) _bytes -= previous.bytes.length;
  while (_pages.isNotEmpty &&
      (_bytes + bytes.length > maxBytes || _pages.length >= maxEntries)) {
    _bytes -= _pages.remove(_pages.keys.first)!.bytes.length;
  }
  _pages[key] = DVRenderedPage(bytes, headers);
  _bytes += bytes.length;
}