Class: GemCP::Cache::Entry

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

Overview

A single cached response with freshness metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



13
14
15
# File 'lib/gemcp/cache.rb', line 13

def body
  @body
end

#etagObject (readonly)

Returns the value of attribute etag

Returns:

  • (Object)

    the current value of etag



13
14
15
# File 'lib/gemcp/cache.rb', line 13

def etag
  @etag
end

#last_modifiedObject (readonly)

Returns the value of attribute last_modified

Returns:

  • (Object)

    the current value of last_modified



13
14
15
# File 'lib/gemcp/cache.rb', line 13

def last_modified
  @last_modified
end

#stored_atObject (readonly)

Returns the value of attribute stored_at

Returns:

  • (Object)

    the current value of stored_at



13
14
15
# File 'lib/gemcp/cache.rb', line 13

def stored_at
  @stored_at
end

Instance Method Details

#fresh?(ttl:, now: Time.now) ⇒ Boolean

Returns whether this entry is younger than ttl seconds.

Parameters:

  • ttl (Integer)

    freshness lifetime in seconds

  • now (Time) (defaults to: Time.now)

    current time (injectable for testing)

Returns:

  • (Boolean)

    whether this entry is younger than ttl seconds



17
18
19
# File 'lib/gemcp/cache.rb', line 17

def fresh?(ttl:, now: Time.now)
  now.to_i - stored_at.to_i < ttl
end