DirectoryQuotaManager class
A decoupled, directory-agnostic disk quota manager and LRU cache evictor.
Operates on any given directory to compute disk usage and trim files down to maxBytes using configurable LruSortStrategy.
Constructors
-
DirectoryQuotaManager(Directory directory, {int? maxBytes, double trimRatio = 0.8, LruSortStrategy sortStrategy = LruSortStrategy.latestOfAccessedOrModified, List<
File> companionResolver(File primaryFile)?, DateTime? customTimestampResolver(File primaryFile, List<File> companions)?, Duration minAgeForEviction = const Duration(seconds: 10), Logger? logger})
Properties
-
companionResolver
→ List<
File> Function(File primaryFile)? -
Optional companion resolver returning related sidecar files (e.g.
.meta.json) that must be measured and deleted together with the primary file.final -
customTimestampResolver
→ DateTime? Function(File primaryFile, List<
File> companions)? -
Optional custom timestamp extractor. If provided, overrides sortStrategy.
final
- directory → Directory
-
The target directory being managed.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger → Logger?
-
Optional logger for recording quota management, pruning, and file evictions.
final
- maxBytes → int?
-
The maximum disk space quota (in bytes). Null means no quota limit.
final
- minAgeForEviction → Duration
-
Minimum age an entry must have before it can be considered for eviction.
Protects active in-flight writes from being purged prematurely.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sortStrategy → LruSortStrategy
-
The file timestamp strategy used to order files from oldest to newest.
final
- trimRatio → double
-
The target ratio to trim down to once maxBytes is exceeded (default: 0.8 = 80%).
final
Methods
-
clear(
) → Future< void> - Purges all contents inside directory, preserving the directory itself.
-
getTotalSize(
) → Future< int> - Calculates the total byte size of all files inside directory.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
trim(
{int? targetQuotaBytes}) → Future< int> -
Trims the directory down to
targetQuotaBytes(defaults tomaxBytes * trimRatio).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited