Class: Langfuse::PromptCache::CacheEntry
- Inherits:
-
Struct
- Object
- Struct
- Langfuse::PromptCache::CacheEntry
- Defined in:
- lib/langfuse/prompt_cache.rb
Overview
Cache entry with data and expiration time
Supports stale-while-revalidate pattern:
-
fresh_until: Time until entry is considered fresh (can be served immediately)
-
stale_until: Time until entry is considered stale (serve while revalidating in background)
-
After stale_until: Entry is expired (must revalidate synchronously)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#fresh_until ⇒ Object
Returns the value of attribute fresh_until.
-
#stale_until ⇒ Object
Returns the value of attribute stale_until.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Check if the cache entry has expired.
-
#fresh? ⇒ Boolean
Check if the cache entry is still fresh.
-
#stale? ⇒ Boolean
Check if the cache entry is stale but not expired.
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data
33 34 35 |
# File 'lib/langfuse/prompt_cache.rb', line 33 def data @data end |
#fresh_until ⇒ Object
Returns the value of attribute fresh_until
33 34 35 |
# File 'lib/langfuse/prompt_cache.rb', line 33 def fresh_until @fresh_until end |
#stale_until ⇒ Object
Returns the value of attribute stale_until
33 34 35 |
# File 'lib/langfuse/prompt_cache.rb', line 33 def stale_until @stale_until end |
Instance Method Details
#expired? ⇒ Boolean
Check if the cache entry has expired
Expired entries should not be served and must be revalidated synchronously before use.
58 59 60 |
# File 'lib/langfuse/prompt_cache.rb', line 58 def expired? Time.now >= stale_until end |
#fresh? ⇒ Boolean
Check if the cache entry is still fresh
37 38 39 |
# File 'lib/langfuse/prompt_cache.rb', line 37 def fresh? Time.now < fresh_until end |
#stale? ⇒ Boolean
Check if the cache entry is stale but not expired
Stale entries can be served immediately while a background revalidation occurs (stale-while-revalidate pattern)
47 48 49 50 |
# File 'lib/langfuse/prompt_cache.rb', line 47 def stale? now = Time.now now >= fresh_until && now < stale_until end |