ExLLM.Testing.TestCacheHelpers (ex_llm v0.8.1)
View SourceTest helper functions for managing and working with the automatic test cache.
This module provides convenient functions for test suites to interact with the caching system, including cache warming, clearing, and debugging.
Summary
Functions
Clean up old cache timestamps.
Clear test cache with different scopes.
Deduplicate cache content to save space.
Disable debug logging for cache operations.
Enable debug logging for cache operations.
Force cache miss for specific patterns.
Force cache refresh for specific patterns.
Get cache statistics for specific test module.
List all cache timestamps for a pattern.
Print cache statistics summary.
Print cache statistics by provider.
Restore cache from a specific timestamp.
Set fallback strategy for specific test patterns.
Set custom TTL for specific test patterns.
Setup hook for test modules to initialize caching.
Verify cache integrity and check for issues.
Warm test cache for specific test modules or patterns.
Run a test with specific cache configuration.
Functions
Clean up old cache timestamps.
Clear test cache with different scopes.
Examples
# Clear all cache
clear_test_cache(:all)
# Clear specific provider
clear_test_cache("anthropic")
# Clear specific test module
clear_test_cache("AnthropicIntegrationTest")
Deduplicate cache content to save space.
Disable debug logging for cache operations.
Enable debug logging for cache operations.
Force cache miss for specific patterns.
Useful for testing real API calls without disabling cache entirely.
Force cache refresh for specific patterns.
Ignores TTL and forces fresh API calls.
Get cache statistics for specific test module.
List all cache timestamps for a pattern.
Examples
list_cache_timestamps("anthropic/chat_basic")
Print cache statistics summary.
Print cache statistics by provider.
Restore cache from a specific timestamp.
Useful for debugging or testing with older responses.
Set fallback strategy for specific test patterns.
Set custom TTL for specific test patterns.
Setup hook for test modules to initialize caching.
Usage in test module:
setup do
ExLLM.Testing.TestCacheHelpers.setup_test_cache()
end
Verify cache integrity and check for issues.
Warm test cache for specific test modules or patterns.
This pre-loads cache entries that might be expiring soon.
Run a test with specific cache configuration.
Examples
with_test_cache([ttl: :timer.hours(1)], fn ->
# Your test code here
end)