CacheEntry<T> class

Represents a cached data entry with metadata for staleness and eviction.

Each cache entry stores the data along with timestamps and access counts used for staleness detection and cache eviction policies.

Constructors

CacheEntry({required T data, required DateTime createdAt, required DateTime lastAccessedAt, required int accessCount, required Duration staleTime, required Duration cacheTime, int referenceCount = 0, bool isSecure = false, DateTime? expiresAt, bool hasValue = true})
Creates a CacheEntry with the given data and metadata.
const
CacheEntry.create({required T data, required Duration staleTime, required Duration cacheTime, bool isSecure = false, Duration? maxAge, bool hasValue = true})
Creates a new cache entry with current timestamp.
factory

Properties

accessCount int
How many times this data has been accessed.
final
age Duration
The age of this cache entry.
no setter
cacheTime Duration
How long inactive data stays in cache.
final
createdAt DateTime
When this data was fetched.
final
data → T
The cached data.
final
expiresAt DateTime?
When this secure entry expires (enforced TTL).
final
hashCode int
The hash code for this object.
no setterinherited
hasValue bool
Whether this entry represents a cached value (even if the value is null).
final
isExpired bool
Whether this secure entry has expired (TTL exceeded).
no setter
isFresh bool
Whether the data is still fresh.
no setter
isSecure bool
Whether this entry contains sensitive data.
final
isStale bool
Whether the data is stale.
no setter
lastAccessedAt DateTime
When this data was last accessed.
final
referenceCount int
Reference count for active queries using this data.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
staleTime Duration
How long this data stays fresh.
final

Methods

copyWith({T? data, DateTime? createdAt, DateTime? lastAccessedAt, int? accessCount, Duration? staleTime, Duration? cacheTime, int? referenceCount, bool? isSecure, DateTime? expiresAt, bool? hasValue}) CacheEntry<T>
Creates a copy with updated metadata.
estimateSize() int
Estimates the size of this entry in bytes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
shouldGarbageCollect(DateTime now) bool
Whether the entry should be garbage collected.
toString() String
A string representation of this object.
override
withAccess() CacheEntry<T>
Creates a copy with updated access metadata.

Operators

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