toString(), suffix: $stateHash ); } /** * Create cache key for slot content */ public static function forSlot(ComponentId $componentId, string $slotName): self { return new self( type: 'slot', identifier: $componentId->toString(), suffix: $slotName ); } /** * Create cache key for template fragment */ public static function forTemplate(string $componentType, string $variant = 'default'): self { return new self( type: 'template', identifier: $componentType, suffix: $variant ); } /** * Create cache key for rendered output */ public static function forRenderedOutput(ComponentId $componentId, string $stateHash): self { return new self( type: 'rendered', identifier: $componentId->toString(), suffix: $stateHash ); } /** * Create cache key for component metadata */ public static function forMetadata(string $componentType): self { return new self( type: 'metadata', identifier: $componentType, suffix: '' ); } /** * Get cache key as string */ public function toString(): string { $parts = [self::PREFIX, $this->type, $this->identifier]; if (! empty($this->suffix)) { $parts[] = $this->suffix; } return implode(':', $parts); } /** * Convert to framework CacheKey */ public function toCacheKey(): CacheKey { return CacheKey::fromString($this->toString()); } /** * Get cache key type */ public function getType(): string { return $this->type; } /** * Get identifier part */ public function getIdentifier(): string { return $this->identifier; } /** * Get suffix part */ public function getSuffix(): string { return $this->suffix; } /** * Check if this key matches a pattern */ public function matches(string $pattern): bool { return fnmatch($pattern, $this->toString()); } /** * Get wildcard pattern for invalidation */ public static function wildcardForComponent(ComponentId $componentId): string { return self::PREFIX . ':*:' . $componentId->toString() . ':*'; } /** * Get wildcard pattern for type */ public static function wildcardForType(string $type): string { return self::PREFIX . ':' . $type . ':*'; } }