- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
104 lines
3.1 KiB
PHP
104 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Discovery\ValueObjects;
|
|
|
|
/**
|
|
* Cache level enumeration for memory-aware caching
|
|
*
|
|
* Defines different cache retention and compression strategies
|
|
* based on memory pressure conditions.
|
|
*/
|
|
enum CacheLevel: string
|
|
{
|
|
case MINIMAL = 'minimal'; // Critical memory: very short TTL, maximum compression
|
|
case REDUCED = 'reduced'; // High pressure: reduced TTL, high compression
|
|
case COMPRESSED = 'compressed'; // Medium pressure: normal TTL, medium compression
|
|
case NORMAL = 'normal'; // Normal memory: standard caching behavior
|
|
case EXTENDED = 'extended'; // Low memory usage: extended TTL, no compression
|
|
|
|
/**
|
|
* Get cache retention multiplier for this level
|
|
*/
|
|
public function getRetentionMultiplier(): float
|
|
{
|
|
return match ($this) {
|
|
self::MINIMAL => 0.1,
|
|
self::REDUCED => 0.5,
|
|
self::COMPRESSED => 0.75,
|
|
self::NORMAL => 1.0,
|
|
self::EXTENDED => 1.5
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get compression requirement for this level
|
|
*/
|
|
public function requiresCompression(): bool
|
|
{
|
|
return match ($this) {
|
|
self::MINIMAL, self::REDUCED, self::COMPRESSED => true,
|
|
self::NORMAL, self::EXTENDED => false
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get default compression level for this cache level
|
|
*/
|
|
public function getDefaultCompressionLevel(): CompressionLevel
|
|
{
|
|
return match ($this) {
|
|
self::MINIMAL => CompressionLevel::MAXIMUM,
|
|
self::REDUCED => CompressionLevel::HIGH,
|
|
self::COMPRESSED => CompressionLevel::MEDIUM,
|
|
self::NORMAL => CompressionLevel::LOW,
|
|
self::EXTENDED => CompressionLevel::NONE
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get description of this cache level
|
|
*/
|
|
public function getDescription(): string
|
|
{
|
|
return match ($this) {
|
|
self::MINIMAL => 'Minimal caching with maximum compression and very short TTL',
|
|
self::REDUCED => 'Reduced caching with high compression and short TTL',
|
|
self::COMPRESSED => 'Normal caching with medium compression',
|
|
self::NORMAL => 'Standard caching behavior',
|
|
self::EXTENDED => 'Extended caching with longer TTL and no compression'
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check if this level is more aggressive than another
|
|
*/
|
|
public function isMoreAggressiveThan(self $other): bool
|
|
{
|
|
$levels = [
|
|
self::EXTENDED => 0,
|
|
self::NORMAL => 1,
|
|
self::COMPRESSED => 2,
|
|
self::REDUCED => 3,
|
|
self::MINIMAL => 4,
|
|
];
|
|
|
|
return $levels[$this] > $levels[$other];
|
|
}
|
|
|
|
/**
|
|
* Suggest cache level based on memory pressure
|
|
*/
|
|
public static function fromMemoryPressure(float $pressure): self
|
|
{
|
|
return match (true) {
|
|
$pressure >= 0.95 => self::MINIMAL,
|
|
$pressure >= 0.85 => self::REDUCED,
|
|
$pressure >= 0.75 => self::COMPRESSED,
|
|
$pressure >= 0.30 => self::NORMAL,
|
|
default => self::EXTENDED
|
|
};
|
|
}
|
|
}
|