toString(); if (isset($this->storage[$key])) { $items[] = \App\Framework\Cache\CacheItem::hit($identifier, $this->storage[$key]['value']); } else { $items[] = \App\Framework\Cache\CacheItem::miss($identifier); } } return \App\Framework\Cache\CacheResult::fromItems(...$items); } public function set(\App\Framework\Cache\CacheItem ...$items): bool { foreach ($items as $item) { $this->storage[$item->key->toString()] = [ 'value' => $item->value, 'ttl' => $item->ttl, ]; } return true; } public function has(\App\Framework\Cache\CacheIdentifier ...$identifiers): array { $results = []; foreach ($identifiers as $identifier) { $results[$identifier->toString()] = isset($this->storage[$identifier->toString()]); } return $results; } public function forget(\App\Framework\Cache\CacheIdentifier ...$identifiers): bool { foreach ($identifiers as $identifier) { unset($this->storage[$identifier->toString()]); } return true; } public function clear(): bool { $this->storage = []; return true; } public function remember(\App\Framework\Cache\CacheKey $key, callable $callback, ?\App\Framework\Core\ValueObjects\Duration $ttl = null): \App\Framework\Cache\CacheItem { $result = $this->get($key); $item = $result->getItem($key); if ($item->isHit) { return $item; } $value = $callback(); $this->set(\App\Framework\Cache\CacheItem::forSet($key, $value, $ttl)); return \App\Framework\Cache\CacheItem::hit($key, $value); } }; echo "1. Testing Default Constructor Behavior:\n\n"; try { // Create SmartCache with default constructor (should auto-enable strategies) $smartCache = new SmartCache($mockCache); echo " āœ… SmartCache created with default constructor\n"; // Check if strategies are enabled $stats = $smartCache->getStats(); $strategySupport = $stats['strategy_support'] ?? false; $strategyManager = $smartCache->getStrategyManager(); echo " šŸ“Š Strategy support: " . ($strategySupport ? 'YES' : 'NO') . "\n"; if ($strategyManager) { $managerStats = $strategyManager->getStats(); echo " šŸ“Š Total strategies: {$managerStats['strategy_manager']['total_strategies']}\n"; echo " šŸ“Š Enabled strategies: {$managerStats['strategy_manager']['enabled_strategies']}\n"; echo " šŸ“Š Strategy names: " . implode(', ', $managerStats['strategy_manager']['strategy_names']) . "\n"; } echo "\n"; } catch (\Throwable $e) { echo " āŒ Error testing default constructor: {$e->getMessage()}\n\n"; } echo "2. Testing Strategy Auto-Activation with Cache Operations:\n\n"; try { $smartCache = new SmartCache($mockCache); $testKey = CacheKey::fromString('auto_strategy_test'); echo " šŸ”§ Testing cache operations with auto-enabled strategies:\n"; // Test cache set with TTL modification by strategies $originalTtl = Duration::fromMinutes(30); $smartCache->set(CacheItem::forSet($testKey, "test_value", $originalTtl)); echo " āœ… Cache SET operation completed\n"; // Test cache get with strategy access tracking $result = $smartCache->get($testKey); $item = $result->getItem($testKey); echo " āœ… Cache GET operation completed: " . ($item->isHit ? 'HIT' : 'MISS') . "\n"; // Test remember operation with strategy integration $rememberResult = $smartCache->remember( CacheKey::fromString('remember_test'), fn () => "remembered_value", Duration::fromHours(1) ); echo " āœ… Cache REMEMBER operation completed: " . ($rememberResult->isHit ? 'HIT' : 'MISS') . "\n"; // Check if strategies have recorded activity $adaptiveStats = $smartCache->getStrategyStats('adaptive_ttl'); if ($adaptiveStats) { echo " šŸ“Š Adaptive TTL tracked keys: {$adaptiveStats['total_tracked_keys']}\n"; } $heatMapStats = $smartCache->getStrategyStats('heat_map'); if ($heatMapStats) { echo " šŸ“Š Heat Map tracked keys: {$heatMapStats['total_tracked_keys']}\n"; } echo "\n"; } catch (\Throwable $e) { echo " āŒ Error testing strategy auto-activation: {$e->getMessage()}\n\n"; } echo "3. Testing Explicit Strategy Control:\n\n"; try { // Test withoutStrategies method echo " 🚫 Testing explicit strategy disabling:\n"; $noStrategyCache = SmartCache::withoutStrategies($mockCache); $noStrategyStats = $noStrategyCache->getStats(); $hasStrategies = $noStrategyStats['strategy_support'] ?? false; echo " āœ… Cache without strategies created\n"; echo " šŸ“Š Strategy support: " . ($hasStrategies ? 'YES' : 'NO') . "\n"; // Test withDefaultStrategies method (explicit activation) echo "\n ✨ Testing explicit strategy enabling:\n"; $explicitStrategyCache = SmartCache::withDefaultStrategies($mockCache); $explicitStats = $explicitStrategyCache->getStats(); $explicitHasStrategies = $explicitStats['strategy_support'] ?? false; echo " āœ… Cache with explicit strategies created\n"; echo " šŸ“Š Strategy support: " . ($explicitHasStrategies ? 'YES' : 'NO') . "\n"; echo "\n"; } catch (\Throwable $e) { echo " āŒ Error testing explicit strategy control: {$e->getMessage()}\n\n"; } echo "4. Testing Performance vs Intelligence Trade-off:\n\n"; try { echo " ⚔ Comparing cache configurations:\n"; // Without strategies (maximum performance) $performanceCache = SmartCache::withoutStrategies($mockCache); // With default strategies (balanced intelligence) $intelligentCache = new SmartCache($mockCache); // Uses default strategies // With performance strategies (performance-focused intelligence) $perfOptimizedCache = SmartCache::withPerformanceStrategies($mockCache); echo " āœ… Performance Cache (no strategies): Strategy support = " . ($performanceCache->getStats()['strategy_support'] ? 'YES' : 'NO') . "\n"; echo " āœ… Intelligent Cache (default strategies): Strategy support = " . ($intelligentCache->getStats()['strategy_support'] ? 'YES' : 'NO') . "\n"; echo " āœ… Performance-Optimized Cache (perf strategies): Strategy support = " . ($perfOptimizedCache->getStats()['strategy_support'] ? 'YES' : 'NO') . "\n"; echo "\n"; } catch (\Throwable $e) { echo " āŒ Error testing performance configurations: {$e->getMessage()}\n\n"; } echo "=== Default Strategies Auto-Activation Test Completed ===\n"; echo "\nšŸŽÆ Summary:\n"; echo " • āœ… SmartCache constructor now auto-enables Default Strategies\n"; echo " • āœ… Strategy support is active by default for intelligence\n"; echo " • āœ… SmartCache::withoutStrategies() available for maximum performance\n"; echo " • āœ… Backward compatibility maintained with explicit methods\n"; echo " • āœ… Convention over Configuration philosophy implemented\n"; echo "\nšŸ’” Usage:\n"; echo " new SmartCache(\$cache) → WITH strategies (default)\n"; echo " SmartCache::withDefaultStrategies(\$cache) → WITH strategies (explicit)\n"; echo " SmartCache::withoutStrategies(\$cache) → WITHOUT strategies (performance)\n";