Skip to content

Conversation

@koxudaxi
Copy link
Collaborator

@koxudaxi koxudaxi commented Oct 30, 2025

TL;DR

Added cache clearing functionality for LLM client singletons to improve test isolation and provide a way to reset client state.

What changed?

  • Added clear_cache() methods to all LLM client implementations (Anthropic, Azure OpenAI, Google, OpenAI)
  • Created a new cache.py module with a clear_all_client_caches() function that clears all client caches at once
  • Exposed the cache clearing functions through appropriate __init__.py files
  • Added an autouse pytest fixture in tests/e2e/conftest.py that clears client caches before and after each e2e test

How to test?

  1. Import and call clear_all_client_caches() in a test or application code
  2. Verify that subsequent client creation returns fresh instances
  3. Run e2e tests to confirm they execute correctly with the new cache clearing fixture

Why make this change?

This change improves test isolation by ensuring that cached LLM client singletons don't persist between tests, which could lead to test interference. It also provides a way for users to explicitly reset client state when needed, such as when changing API keys or endpoints during runtime.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 30, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
v2-docs 1071cdd Oct 30 2025, 02:50 AM

@koxudaxi koxudaxi marked this pull request as ready for review October 30, 2025 03:20
@koxudaxi koxudaxi requested a review from willbakst as a code owner October 30, 2025 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants