PdfBudgetedCache<K, V> constructor
PdfBudgetedCache<K, V> ({})
Creates a cache bounded by maxWeight (using weigher) and/or
maxEntries. At least one bound should be given or the cache grows
without limit. maxEntries is floored at 1 so the cache always keeps the
most-recently-used entry. When clearsUnderMemoryPressure is set the
cache registers with PdfCacheRegistry for its lifetime (until
dispose).
Implementation
PdfBudgetedCache({
int Function(V value)? weigher,
int? maxWeight,
int? maxEntries,
void Function(V value)? disposer,
V Function(V value)? cloner,
void Function(K key, V value)? onEvicted,
bool rejectOversize = false,
bool clearsUnderMemoryPressure = false,
this.debugLabel = 'cache',
}) : _weigher = weigher,
_maxWeight = maxWeight ?? 0,
_hasWeightBudget = weigher != null && maxWeight != null,
_maxEntries = maxEntries == null ? null : math.max(1, maxEntries),
_disposer = disposer,
_cloner = cloner,
_onEvicted = onEvicted,
_rejectOversize = rejectOversize,
_clearsUnderMemoryPressure = clearsUnderMemoryPressure {
if (_clearsUnderMemoryPressure) PdfCacheRegistry.instance.register(this);
}