Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function load(): void
return;
}

$this->clear();
$this->clear(false);

try {
$cached = $this->cache->get(self::DISCOVERED_ELEMENTS_CACHE_KEY);
Expand Down Expand Up @@ -176,8 +176,6 @@ public function load(): void
$this->logger->debug("Loaded {$loadCount} elements from cache.");
} catch (CacheInvalidArgumentException $e) {
$this->logger->error('Invalid registry cache key used.', ['key' => self::DISCOVERED_ELEMENTS_CACHE_KEY, 'exception' => $e]);
} catch (DefinitionException $e) {
$this->logger->error('Error hydrating definition from cache.', ['exception' => $e]);
} catch (Throwable $e) {
$this->logger->error('Unexpected error loading from cache.', ['key' => self::DISCOVERED_ELEMENTS_CACHE_KEY, 'exception' => $e]);
}
Expand Down Expand Up @@ -351,9 +349,14 @@ public function hasElements(): bool
|| ! empty($this->resourceTemplates);
}

public function clear(): void
/**
* Clear discovered elements from registry
*
* @param bool $includeCache Whether to clear the cache as well (default: true)
*/
public function clear(bool $includeCache = true): void
{
if ($this->cache !== null) {
if ($includeCache && $this->cache !== null) {
try {
$this->cache->delete(self::DISCOVERED_ELEMENTS_CACHE_KEY);
$this->logger->debug('Registry cache cleared.');
Expand Down Expand Up @@ -438,24 +441,24 @@ public function getPrompt(string $name): ?RegisteredPrompt
/** @return array<string, Tool> */
public function getTools(): array
{
return array_map(fn ($tool) => $tool->schema, $this->tools);
return array_map(fn($tool) => $tool->schema, $this->tools);
}

/** @return array<string, Resource> */
public function getResources(): array
{
return array_map(fn ($resource) => $resource->schema, $this->resources);
return array_map(fn($resource) => $resource->schema, $this->resources);
}

/** @return array<string, Prompt> */
public function getPrompts(): array
{
return array_map(fn ($prompt) => $prompt->schema, $this->prompts);
return array_map(fn($prompt) => $prompt->schema, $this->prompts);
}

/** @return array<string, ResourceTemplate> */
public function getResourceTemplates(): array
{
return array_map(fn ($template) => $template->schema, $this->resourceTemplates);
return array_map(fn($template) => $template->schema, $this->resourceTemplates);
}
}