CacheItem<T> class
A class that represents a single item in the cache.
Each cache item contains a value, optional expiry time, and other metadata.
Constructors
-
CacheItem.new({required T value, DateTime? expiry, Duration? slidingExpiry, CachePriority priority = CachePriority.normal, DateTime? createdAt, DateTime? lastAccessedAt, int accessCount = 0, bool isCompressed = false, int? originalSize, double? compressionRatio, Set<
String> ? tags}) - Creates a new instance of CacheItem.
-
CacheItem.fromJson(Map<
String, dynamic> json) -
Creates a cache item from a JSON map.
factory
Properties
- accessCount ↔ int
-
The number of times the item has been accessed.
getter/setter pair
- compressionRatio → double?
-
The compression ratio achieved (original size / compressed size).
This is only set if the item is compressed.
final
- createdAt → DateTime
-
The time at which the item was created.
final
- expiry → DateTime?
-
The time at which the item expires and should be removed from the cache.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isCompressed → bool
-
Whether the item is compressed.
final
- isExpired → bool
-
no setter
- lastAccessedAt ↔ DateTime
-
The time at which the item was last accessed.
getter/setter pair
- originalSize → int?
-
The original size of the item before compression, in bytes.
This is only set if the item is compressed.
final
- priority → CachePriority
-
The priority of the item. Higher priority items are less likely to be evicted when the cache is full.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- slidingExpiry → Duration?
-
The sliding expiry duration. If set, the expiry time will be extended by this duration each time the item is accessed.
final
-
The tags associated with this cache item.
Tags can be used to group related items and perform operations on them as a group.
final
- value → T
-
The value stored in the cache.
final
Methods
-
isStale(
Duration staleTime) → bool - Checks if the item is stale based on the provided stale time.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Converts the cache item to a JSON map.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateExpiry(
) → CacheItem< T> - Updates the expiry time of the item based on the sliding expiry duration.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited