Class: Aikido::Zen::CacheEntry

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

Constant Summary collapse

DEFAULT_CLOCK =
-> { Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, ttl:, clock: nil) ⇒ Aikido::Zen::CacheEntry

Parameters:

  • value (Object)

    the value

  • ttl (Integer)

    the time-to-live in milliseconds



75
76
77
78
79
80
81
# File 'lib/aikido/zen/cache.rb', line 75

def initialize(value, ttl:, clock: nil)
  @value = value
  @ttl = ttl
  @clock = clock || DEFAULT_CLOCK

  refresh
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



68
69
70
# File 'lib/aikido/zen/cache.rb', line 68

def value
  @value
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/aikido/zen/cache.rb', line 87

def expired?
  @clock.call >= @expires
end

#refreshObject



83
84
85
# File 'lib/aikido/zen/cache.rb', line 83

def refresh
  @expires = @clock.call + @ttl
end