setMaxSize method
Sets the maximum cache size (applies mainly to in-memory cache).
maxSize - Maximum number of elements. If null, no limit
evictionPolicy - Eviction policy when the limit is reached
Implementation
@override
Future<void> setMaxSize(
int? maxSize, {
EvictionPolicy? evictionPolicy,
}) async {
_maxSize = maxSize;
if (evictionPolicy != null) {
_evictionPolicy = evictionPolicy;
}
// If new max size is smaller than current size, evict entries
if (_maxSize != null && _cache.length > _maxSize!) {
final entriesToEvict = _cache.length - _maxSize!;
for (int i = 0; i < entriesToEvict; i++) {
_evictOneEntry();
}
}
}