CacheStats class
Common cache statistics interface and implementation for all cache drivers.
This provides a standardized way to track and report cache performance metrics across different cache implementations (memory, file, Redis, etc.).
Usage
// In a cache driver implementation
final stats = CacheStats();
stats.hits++;
// Get statistics
final hitRate = stats.hitRate;
final totalOperations = stats.totalOperations;
Constructors
- CacheStats()
- Creates a new CacheStats instance with default values.
-
CacheStats.fromJson(Map<
String, dynamic> json) -
Creates a CacheStats instance from a JSON map.
factory
- CacheStats.withValues({int hits = 0, int misses = 0, int sets = 0, int deletions = 0, int expirations = 0, int clears = 0})
- Creates a CacheStats instance with specific values.
Properties
- clears ↔ int
-
Number of cache clears
getter/setter pair
- deletions ↔ int
-
Number of cache deletions
getter/setter pair
- expirations ↔ int
-
Number of expired entries encountered
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setteroverride
- hitRate → double
-
Calculates the cache hit rate as a percentage.
no setter
- hits ↔ int
-
Number of cache hits (successful retrievals)
getter/setter pair
- misses ↔ int
-
Number of cache misses (failed retrievals)
getter/setter pair
- readOperations → int
-
Gets the total number of read operations (hits + misses).
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sets ↔ int
-
Number of cache writes/sets
getter/setter pair
- totalOperations → int
-
Gets the total number of cache operations.
no setter
- writeOperations → int
-
Gets the total number of write operations (sets + deletions + clears).
no setter
Methods
-
copy(
) → CacheStats - Creates a copy of this CacheStats instance.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
) → void - Resets all statistics to zero.
-
toJson(
) → Map< String, dynamic> - Converts the statistics to a JSON-compatible map.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override