Class: WorkOS::Cache::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/cache.rb

Overview

The Entry class represents a cache entry with a value and an expiration time

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, expires_in_seconds) ⇒ Entry

Initializes a new cache entry

Parameters:

  • value (Object)

    The value to store in the cache

  • expires_in_seconds (Integer, nil)

    The expiration time for the value in seconds, or nil for no expiration



14
15
16
17
# File 'lib/workos/cache.rb', line 14

def initialize(value, expires_in_seconds)
  @value = value
  @expires_at = expires_in_seconds ? Time.now + expires_in_seconds : nil
end

Instance Attribute Details

#expires_atObject (readonly)

Returns the value of attribute expires_at.



9
10
11
# File 'lib/workos/cache.rb', line 9

def expires_at
  @expires_at
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/workos/cache.rb', line 9

def value
  @value
end

Instance Method Details

#expired?Boolean

Checks if the entry has expired

Returns:

  • (Boolean)

    True if the entry has expired, false otherwise



21
22
23
24
25
# File 'lib/workos/cache.rb', line 21

def expired?
  return false if expires_at.nil?

  Time.now > @expires_at
end