BackgroundCompactor class
Background compaction for Rift boxes. Performs incremental compaction without blocking reads.
The BackgroundCompactor runs compaction on registered boxes at regular intervals. This is useful for long-running applications where boxes accumulate deleted/overwritten entries that need to be cleaned up periodically.
Compaction is non-blocking: reads can proceed while compaction is in progress since Rift's architecture supports concurrent reads.
Usage:
final compactor = BackgroundCompactor(
{'users': usersBox, 'settings': settingsBox},
interval: Duration(minutes: 10),
);
compactor.start();
// Listen for compaction events
compactor.events.listen((event) {
print('${event.boxName} compacted in ${event.duration.inMilliseconds}ms');
});
// Stop when done
compactor.stop();
Constructors
-
BackgroundCompactor(Map<
String, Box> _boxes, {Duration interval = const Duration(minutes: 5)}) -
Create a BackgroundCompactor for the given
boxes.
Properties
- compactionCount → int
-
The total number of compactions performed.
no setter
-
events
→ Stream<
CompactionEvent> -
Stream of compaction events.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- interval → Duration
-
The current compaction interval.
no setter
- isRunning → bool
-
Whether the compactor is currently running.
no setter
-
registeredBoxNames
→ Iterable<
String> -
Get the names of all registered boxes.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
compactAll(
) → Future< void> - Compact all registered boxes.
-
compactBox(
String boxName) → Future< void> -
Compact a specific box by
boxName. -
dispose(
) → void - Dispose of the compactor, stopping the timer and closing the event stream.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerBox(
String name, Box box) → void - Register an additional box for compaction.
-
start(
) → void - Start automatic background compaction.
-
stop(
) → void - Stop automatic compaction.
-
toString(
) → String -
A string representation of this object.
inherited
-
unregisterBox(
String name) → void - Unregister a box from compaction.
-
updateInterval(
Duration newInterval) → void - Update the compaction interval.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited