You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(config): Use :indefinite symbol instead of Float::INFINITY for cache_stale_ttl
Improves API ergonomics by replacing Float::INFINITY with a more Ruby-idiomatic
:indefinite symbol for never-expiring cache configuration.
Rationale:
- :indefinite is more readable and Ruby-idiomatic than Float::INFINITY
- Symbols are the conventional way to represent special values in Ruby config
- Makes intent clearer in configuration code
- Aligns with Ruby community conventions (e.g., Rails cache :expires_in)
Changes:
- Renamed THOUSAND_YEARS_IN_SECONDS constant to INDEFINITE_SECONDS
- Updated constant comment to clarify intent ("indefinite cache duration")
- Changed normalize_stale_ttl from class method to instance method (normalized_stale_ttl)
- Instance method reads from cache_stale_ttl and returns normalized value on-demand
- Removed normalization from Config#initialize (now done lazily via method)
- Updated create_memory_cache to use config.normalized_stale_ttl
- Updated create_rails_cache_adapter to use config.normalized_stale_ttl
- Updated validate_swr_config! to handle :indefinite symbol properly
- Updated validation error message: "must be non-negative or :indefinite"
Documentation Updates:
- docs/CACHING.md: Changed Float::INFINITY to :indefinite in examples
- docs/CONFIGURATION.md: Changed Float::INFINITY to :indefinite in examples
- lib/langfuse/config.rb: Updated attr_accessor doc to mention :indefinite
- lib/langfuse/prompt_cache.rb: Updated comment to reflect :indefinite normalization
Test Coverage:
- Updated all tests to use :indefinite instead of Float::INFINITY
- Updated all tests to use INDEFINITE_SECONDS instead of THOUSAND_YEARS_IN_SECONDS
- Updated test expectations for new validation error message
- All 797 examples passing, 96.86% coverage maintained
Benefits:
- More intuitive API for developers (config.cache_stale_ttl = :indefinite)
- Clearer intent in configuration code
- Normalization happens on-demand via instance method
- Original config value preserved (not mutated during initialization)
- Better alignment with Ruby conventions and best practices
0 commit comments