Skip to content

Commit bd0a896

Browse files
committed
docs: Update all comments and RDocs for normalize_stale_ttl refactoring
Clarifies that Float::INFINITY normalization happens at the Config level, not in cache implementations, ensuring accurate documentation across the codebase. Changes: - Updated PromptCache#initialize RDoc to note normalization happens in Config - Updated RailsCacheAdapter#initialize RDoc to note normalization happens in Config - Updated Config#cache_stale_ttl RDoc to document Float::INFINITY support - Added normalization note to CONFIGURATION.md (cache_stale_ttl section) - Added normalization note to CACHING.md (Never-Expiring Cache section) - All documentation now accurately reflects the normalized value flow Benefits: - Developers understand where normalization occurs - Cache class documentation is accurate (receives normalized values) - Config documentation explains Float::INFINITY handling - Consistent messaging across code and documentation
1 parent b8becff commit bd0a896

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

docs/CACHING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,12 @@ Langfuse.configure do |config|
198198
config.cache_backend = :memory
199199
config.cache_ttl = 300 # Still refreshes every 5 minutes
200200
config.cache_stale_while_revalidate = true
201-
config.cache_stale_ttl = Float::INFINITY # Never expire (serve stale forever)
201+
config.cache_stale_ttl = Float::INFINITY # Never expire (normalized to 1000 years internally)
202202
end
203203
```
204204

205+
**Note:** `Float::INFINITY` is automatically normalized to 1000 years (31,557,600,000 seconds) during configuration initialization. This provides a practical "never expire" behavior while keeping the value finite for calculations.
206+
205207
### Cache States
206208

207209
SWR introduces three cache states instead of two:

docs/CONFIGURATION.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ See [CACHING.md](CACHING.md#stale-while-revalidate-swr) for detailed usage.
147147
- **Type:** Integer (seconds) or `Float::INFINITY`
148148
- **Default:** `0` (SWR disabled)
149149
- **Description:** Grace period for serving stale data during background refresh
150+
- **Note:** `Float::INFINITY` is automatically normalized to 1000 years (31,557,600,000 seconds) during config initialization
150151

151152
```ruby
152153
config.cache_stale_ttl = 300 # Serve stale data for up to 5 minutes
153-
config.cache_stale_ttl = Float::INFINITY # Never expire (1000 years)
154+
config.cache_stale_ttl = Float::INFINITY # Never expire (normalized to 1000 years internally)
154155
```
155156

156157
**How it works:**

lib/langfuse/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Config
5050
attr_accessor :cache_stale_while_revalidate
5151

5252
# @return [Integer] Stale TTL in seconds (grace period for serving stale data, default: 0 when SWR disabled, cache_ttl when SWR enabled)
53+
# Accepts Float::INFINITY which is automatically normalized to 1000 years (31,557,600,000 seconds) for practical "never expire" behavior.
5354
attr_accessor :cache_stale_ttl
5455

5556
# @return [Integer] Number of background threads for cache refresh

lib/langfuse/prompt_cache.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def expired?
5959
#
6060
# @param ttl [Integer] Time-to-live in seconds (default: 60)
6161
# @param max_size [Integer] Maximum cache size (default: 1000)
62-
# @param stale_ttl [Integer, Float::INFINITY, nil] Stale TTL for SWR (default: 0, SWR disabled). Use Float::INFINITY for 1000 years, e.g. non-expiring cache.
62+
# @param stale_ttl [Integer] Stale TTL for SWR in seconds (default: 0, SWR disabled).
63+
# Note: Float::INFINITY is normalized to 1000 years by Config before being passed here.
6364
# @param refresh_threads [Integer] Number of background refresh threads (default: 5)
6465
# @param logger [Logger, nil] Logger instance for error reporting (default: nil, creates new logger)
6566
def initialize(ttl: 60, max_size: 1000, stale_ttl: 0, refresh_threads: 5, logger: default_logger)

lib/langfuse/rails_cache_adapter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class RailsCacheAdapter
2424
# @param ttl [Integer] Time-to-live in seconds (default: 60)
2525
# @param namespace [String] Cache key namespace (default: "langfuse")
2626
# @param lock_timeout [Integer] Lock timeout in seconds for stampede protection (default: 10)
27-
# @param stale_ttl [Integer, Float::INFINITY, nil] Stale TTL for SWR (default: 0, SWR disabled). Use Float::INFINITY for 1000 years, e.g. non-expiring cache.
27+
# @param stale_ttl [Integer] Stale TTL for SWR in seconds (default: 0, SWR disabled).
28+
# Note: Float::INFINITY is normalized to 1000 years by Config before being passed here.
2829
# @param refresh_threads [Integer] Number of background refresh threads (default: 5)
2930
# @param logger [Logger, nil] Logger instance for error reporting (default: nil, creates new logger)
3031
# @raise [ConfigurationError] if Rails.cache is not available

0 commit comments

Comments
 (0)