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
26 27 28 |
# File 'lib/langfuse/prompt_cache.rb', line 26 def data @data end |
#fresh_until ⇒ Object
Returns the value of attribute fresh_until
26 27 28 |
# File 'lib/langfuse/prompt_cache.rb', line 26 def fresh_until @fresh_until end |
#stale_until ⇒ Object
Returns the value of attribute stale_until
26 27 28 |
# File 'lib/langfuse/prompt_cache.rb', line 26 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.
51 52 53 |
# File 'lib/langfuse/prompt_cache.rb', line 51 def expired? Time.now >= stale_until end |
#fresh? ⇒ Boolean
Check if the cache entry is still fresh
30 31 32 |
# File 'lib/langfuse/prompt_cache.rb', line 30 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)
40 41 42 43 |
# File 'lib/langfuse/prompt_cache.rb', line 40 def stale? now = Time.now now >= fresh_until && now < stale_until end |