Class: Langfuse::PromptCache::CacheEntry

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



33
34
35
# File 'lib/langfuse/prompt_cache.rb', line 33

def data
  @data
end

#fresh_untilObject

Returns the value of attribute fresh_until

Returns:

  • (Object)

    the current value of fresh_until



33
34
35
# File 'lib/langfuse/prompt_cache.rb', line 33

def fresh_until
  @fresh_until
end

#stale_untilObject

Returns the value of attribute stale_until

Returns:

  • (Object)

    the current value of 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.

Returns:

  • (Boolean)

    true if current time is at or after stale_until



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

Returns:

  • (Boolean)

    true if current time is before fresh_until



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)

Returns:

  • (Boolean)

    true if current time is between fresh_until and stale_until



47
48
49
50
# File 'lib/langfuse/prompt_cache.rb', line 47

def stale?
  now = Time.now
  now >= fresh_until && now < stale_until
end