intermediate
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import 'dart:async';
|
||||
|
||||
class Debouncer {
|
||||
final Duration debounce;
|
||||
|
||||
Timer? _timer;
|
||||
|
||||
Debouncer(this.debounce);
|
||||
|
||||
bool get isDebouncing => _timer?.isActive ?? false;
|
||||
|
||||
void eventOccured(void Function() callback) {
|
||||
_timer?.cancel();
|
||||
_timer = Timer(debounce, callback);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class LRUCache<K, V> {
|
||||
return value;
|
||||
}
|
||||
|
||||
void set(K key, V value) {
|
||||
V set(K key, V value) {
|
||||
if (_cache.containsKey(key)) {
|
||||
_cache.remove(key); // Remove the existing item before updating.
|
||||
} else if (_cache.length == _capacity) {
|
||||
@@ -43,6 +43,6 @@ class LRUCache<K, V> {
|
||||
); // Explicitly remove the least recently used item if at capacity.
|
||||
}
|
||||
|
||||
_cache[key] = value; // Inserting or updating the item.
|
||||
return _cache[key] = value; // Inserting or updating the item.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user