Class: Gemkeeper::CompactIndexServer::CacheMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/gemkeeper/compact_index_server/cache_meta.rb

Overview

The sidecar metadata for a cached upstream document: its ETag and when it was fetched. Knows whether it has aged past a TTL and how to serialize.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etag, fetched_at) ⇒ CacheMeta

Returns a new instance of CacheMeta.



18
19
20
21
# File 'lib/gemkeeper/compact_index_server/cache_meta.rb', line 18

def initialize(etag, fetched_at)
  @etag       = etag
  @fetched_at = fetched_at
end

Instance Attribute Details

#etagObject (readonly)

Returns the value of attribute etag.



10
11
12
# File 'lib/gemkeeper/compact_index_server/cache_meta.rb', line 10

def etag
  @etag
end

Class Method Details

.load(hash) ⇒ Object



12
13
14
15
16
# File 'lib/gemkeeper/compact_index_server/cache_meta.rb', line 12

def self.load(hash)
  return nil unless hash

  new(hash["etag"], hash["fetched_at"])
end

Instance Method Details

#expired?(ttl) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/gemkeeper/compact_index_server/cache_meta.rb', line 23

def expired?(ttl)
  return true unless @fetched_at

  Time.now - Time.parse(@fetched_at.to_s) > ttl
rescue ArgumentError
  true
end

#to_hObject



31
# File 'lib/gemkeeper/compact_index_server/cache_meta.rb', line 31

def to_h = { "etag" => @etag, "fetched_at" => @fetched_at }