updateExpiry method

CacheItem<T> updateExpiry()

Updates the expiry time of the item based on the sliding expiry duration.

If the item has a sliding expiry duration, the expiry time will be extended by that duration. Also updates the last accessed time and increments the access count.

Implementation

CacheItem<T> updateExpiry() {
  final now = DateTime.now();
  lastAccessedAt = now;
  accessCount++;

  if (slidingExpiry == null) {
    return this;
  }

  return CacheItem(
    value: value,
    expiry: now.add(slidingExpiry!),
    slidingExpiry: slidingExpiry,
    priority: priority,
    createdAt: createdAt,
    lastAccessedAt: now,
    accessCount: accessCount,
    isCompressed: isCompressed,
    originalSize: originalSize,
    compressionRatio: compressionRatio,
    tags: tags,
  );
}