PrfRolloverCounter class

PrfRolloverCounter is a persistent counter designed to automatically reset after a specified duration from the last update. This is particularly useful for tracking rolling activity windows, such as "submissions per hour" or "attempts every 10 minutes".

Inheritance

Constructors

PrfRolloverCounter.new(String key, {required Duration resetEvery, bool useCache = false})
Constructs a PrfRolloverCounter with a unique key and a specified resetEvery duration. Optionally, caching can be enabled with useCache.

Properties

hashCode int
The hash code for this object.
no setterinherited
lastUpdate BasePrfObject<DateTime>
Provides access to the last update timestamp, considering the caching strategy.
no setterinherited
resetEvery Duration
The duration after which the counter will automatically reset.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
useCache bool
Whether to use in-memory cache for performance.
finalinherited
value BasePrfObject<int>
Provides access to the tracked value, considering the caching strategy.
no setterinherited

Methods

clear() Future<void>
Clears both the value and last update timestamp from storage.
inherited
clearValueOnly() Future<void>
Resets the counter value to its fallback value but retains the last update timestamp.
inherited
fallbackValue() int
Provides the fallback value for the counter, which is zero.
inherited
get() Future<int>
Retrieves the tracked value, resetting it if expired.
inherited
getEndTime() Future<DateTime?>
Determines and returns the DateTime when the current period will end.
getLastUpdateTime() Future<DateTime?>
Retrieves the last update time, or null if never updated.
inherited
hasState() Future<bool>
Checks if either the value or timestamp exists in SharedPreferences.
inherited
increment([int amount = 1]) Future<int>
Increments the counter by amount (default is 1).
inherited
isCurrentlyExpired() Future<bool>
Determines if the tracker is currently expired.
inherited
isExpired(DateTime now, DateTime? last) bool
Determines if the counter is expired based on the current time now and the last update time.
override
isNonZero() Future<bool>
Checks if the counter value is greater than zero.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
peek() Future<int>
Retrieves the value without resetting or updating it.
inherited
percentElapsed() Future<double?>
Computes and returns the progress as a percentage of the reset window.
raw() Future<int>
Retrieves the current raw counter value without checking expiration.
inherited
reset() Future<void>
Resets the counter value to zero and updates the last update time to now.
override
secondsRemaining() Future<int?>
Calculates and returns the number of seconds remaining until the counter resets.
timeRemaining() Future<Duration?>
Calculates and returns the remaining time until the counter auto-resets.
timeSinceLastUpdate() Future<Duration?>
Calculates the duration since the last update, or null if never updated.
inherited
toString() String
A string representation of this object.
inherited
whenExpires() Future<void>
Returns a Future that completes when the rollover period ends.

Operators

operator ==(Object other) bool
The equality operator.
inherited