BaseCounterTracker class abstract

An abstract class for tracking integer counters with expiration logic.

The BaseCounterTracker class extends the BaseTracker to specifically handle integer counters. It provides methods to increment the counter, check if the counter is non-zero, and reset the counter value while maintaining the last update timestamp.

This class is designed to be thread-safe and uses a lock to ensure synchronized access to the counter value.

Inheritance
Implementers

Constructors

BaseCounterTracker.new(String key, {required String suffix, bool useCache = false})
Constructs a BaseCounterTracker with the specified key and suffix.

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
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.
fallbackValue() int
Provides the fallback value for the counter, which is zero.
override
get() Future<int>
Retrieves the tracked value, resetting it if expired.
inherited
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).
isCurrentlyExpired() Future<bool>
Determines if the tracker is currently expired.
inherited
isExpired(DateTime now, DateTime? last) bool
Determines if the tracked value is expired based on the current and last update times.
inherited
isNonZero() Future<bool>
Checks if the counter value is greater than zero.
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
raw() Future<int>
Retrieves the current raw counter value without checking expiration.
reset() Future<void>
Resets the tracked value to its initial state.
inherited
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

Operators

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