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



26
27
28
# File 'lib/langfuse/prompt_cache.rb', line 26

def data
  @data
end

#fresh_untilObject

Returns the value of attribute fresh_until

Returns:

  • (Object)

    the current value of fresh_until



26
27
28
# File 'lib/langfuse/prompt_cache.rb', line 26

def fresh_until
  @fresh_until
end

#stale_untilObject

Returns the value of attribute stale_until

Returns:

  • (Object)

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

Returns:

  • (Boolean)

    true if current time is at or after stale_until



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

Returns:

  • (Boolean)

    true if current time is before fresh_until



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)

Returns:

  • (Boolean)

    true if current time is between fresh_until and stale_until



40
41
42
43
# File 'lib/langfuse/prompt_cache.rb', line 40

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