CachePolicy class

A class that defines the caching policy for an item.

The policy includes settings such as expiry time, priority, refresh strategy, and more.

Constructors

CachePolicy.new({Duration? staleTime, Duration? expiry, Duration? slidingExpiry, CachePriority priority = CachePriority.normal, RefreshStrategy refreshStrategy = RefreshStrategy.never, int? maxSize, bool encrypt = false, CompressionMode compression = CompressionMode.auto, int compressionLevel = 6})
Creates a new instance of CachePolicy.
const

Properties

compression CompressionMode
Whether the cached item should be compressed.
final
compressionLevel int
The compression level to use if compression is enabled.
final
encrypt bool
Whether the cached item should be encrypted.
final
expiry Duration?
The time after which the cached item is considered expired and will be removed from the cache.
final
hashCode int
The hash code for this object.
no setterinherited
maxSize int?
The maximum size of the cached item in bytes.
final
priority CachePriority
The priority of the cached item.
final
refreshStrategy RefreshStrategy
The strategy for refreshing the cached item.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
slidingExpiry Duration?
The sliding expiry time for the cached item.
final
staleTime Duration?
The time after which the cached item is considered stale.
final

Methods

copyWith({Duration? staleTime, Duration? expiry, Duration? slidingExpiry, CachePriority? priority, RefreshStrategy? refreshStrategy, int? maxSize, bool? encrypt}) CachePolicy
Creates a copy of this policy with the specified fields replaced with new values.
createCacheItem<T>(T value) CacheItem<T>
Creates a CacheItem with this policy applied.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

backgroundRefresh({Duration staleTime = const Duration(minutes: 5), Duration expiry = const Duration(days: 1)}) CachePolicy
Cache policy for items that should be refreshed in the background when stale.
compressed({Duration? expiry, CachePriority priority = CachePriority.normal, int compressionLevel = 6}) CachePolicy
Cache policy for large data that should be compressed.
encrypted({Duration? expiry, CachePriority priority = CachePriority.high, CompressionMode compression = CompressionMode.auto}) CachePolicy
Cache policy for sensitive data that should be encrypted.
immediateRefresh({Duration staleTime = const Duration(minutes: 5), Duration expiry = const Duration(days: 1)}) CachePolicy
Cache policy for items that should be refreshed immediately when stale.

Constants

defaultPolicy → const CachePolicy
Default cache policy with normal priority and no automatic refresh.
neverExpire → const CachePolicy
Cache policy for items that should never expire.
temporary → const CachePolicy
Cache policy for temporary data that should be evicted quickly.