cacheAge->lessThan(Duration::fromMinutes(30)); } /** * Check if this is a large cache hit */ public function isLargeCacheHit(): bool { return $this->dataSize?->greaterThan(Byte::fromMegabytes(1)) ?? false; } /** * Get cache efficiency rating */ public function getEfficiencyRating(): string { if ($this->dataSize === null) { return 'unknown'; } return match (true) { $this->isFresh() && ! $this->isLargeCacheHit() => 'optimal', $this->isFresh() => 'good', $this->dataSize->greaterThan(Byte::fromMegabytes(5)) => 'poor', default => 'fair' }; } public function toArray(): array { $baseArray = [ 'cache_key' => (string) $this->cacheKey, 'item_count' => $this->itemCount, 'cache_age_seconds' => $this->cacheAge->toSeconds(), 'cache_age_human' => $this->cacheAge->humanReadable(), 'is_fresh' => $this->isFresh(), 'timestamp' => $this->timestamp->toFloat(), ]; // Add memory-aware fields if available if ($this->dataSize !== null) { $baseArray['data_size'] = $this->dataSize->toHumanReadable(); $baseArray['is_large_hit'] = $this->isLargeCacheHit(); $baseArray['efficiency_rating'] = $this->getEfficiencyRating(); } if ($this->cacheLevel !== null) { $baseArray['cache_level'] = $this->cacheLevel->value; } return $baseArray; } }