perf: cache permitted tools per API key #53

Merged
Snider merged 1 commit from perf/cache-permitted-tools-per-api-key into main 2026-02-23 11:39:06 +00:00
Member

Summary

  • Cache permitted tool names per API key in AgentToolRegistry::forApiKey() using Cache::remember() with a 1-hour TTL, eliminating the O(n) filter on every request (PERF-002)
  • Add flushCacheForApiKey(int|string $id) for explicit invalidation and a CACHE_TTL constant
  • Invalidate cache in AgentApiKeyService::updatePermissions() and revoke() so permission changes take effect immediately
  • Add tests/Unit/AgentToolRegistryTest.php covering cache hit/miss, per-key isolation, scope filtering, TTL constant, and flush behaviour

Test plan

  • ./vendor/bin/pest --filter=AgentToolRegistry passes (all 14 new unit tests)
  • ./vendor/bin/pest full suite passes
  • Verify cache key format agent_tool_registry:api_key:{id} in Redis/cache store
  • Verify cache is cleared when AgentApiKeyService::updatePermissions() is called
  • Verify cache is cleared when AgentApiKeyService::revoke() is called

Closes #24

🤖 Generated with Claude Code

## Summary - Cache permitted tool names per API key in `AgentToolRegistry::forApiKey()` using `Cache::remember()` with a 1-hour TTL, eliminating the O(n) filter on every request (PERF-002) - Add `flushCacheForApiKey(int|string $id)` for explicit invalidation and a `CACHE_TTL` constant - Invalidate cache in `AgentApiKeyService::updatePermissions()` and `revoke()` so permission changes take effect immediately - Add `tests/Unit/AgentToolRegistryTest.php` covering cache hit/miss, per-key isolation, scope filtering, TTL constant, and flush behaviour ## Test plan - [ ] `./vendor/bin/pest --filter=AgentToolRegistry` passes (all 14 new unit tests) - [ ] `./vendor/bin/pest` full suite passes - [ ] Verify cache key format `agent_tool_registry:api_key:{id}` in Redis/cache store - [ ] Verify cache is cleared when `AgentApiKeyService::updatePermissions()` is called - [ ] Verify cache is cleared when `AgentApiKeyService::revoke()` is called Closes #24 🤖 Generated with [Claude Code](https://claude.ai/claude-code)
Clotho added 1 commit 2026-02-23 10:55:43 +00:00
perf: cache permitted tools per API key (closes #24)
Some checks failed
CI / PHP 8.4 (pull_request) Failing after 1m23s
CI / PHP 8.3 (pull_request) Failing after 1m27s
a352f697a9
Cache the list of permitted tool names in `AgentToolRegistry::forApiKey()`
using a 1-hour TTL to avoid O(n) filtering on every request (PERF-002).

- Add `Cache::remember()` in `forApiKey()` storing tool names keyed by API
  key ID (`agent_tool_registry:api_key:{id}`)
- Add `flushCacheForApiKey(int|string $id)` for explicit invalidation
- Add `CACHE_TTL` constant (3600 s) for easy tuning
- Invalidate cache in `AgentApiKeyService::updatePermissions()` and `revoke()`
  so permission changes take effect immediately
- Add `tests/Unit/AgentToolRegistryTest.php` covering cache hit/miss,
  per-key isolation, scope filtering, TTL constant, and flush behaviour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Snider merged commit 8ade82587d into main 2026-02-23 11:39:06 +00:00
Snider deleted branch perf/cache-permitted-tools-per-api-key 2026-02-23 11:39:06 +00:00
Sign in to join this conversation.
No description provided.