Class: Alephant::Broker::LoadStrategy::Revalidate::Strategy

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/broker/load_strategy/revalidate/strategy.rb

Constant Summary collapse

STORAGE_ERRORS =
[Alephant::Broker::Errors::ContentNotFound].freeze

Instance Method Summary collapse

Instance Method Details

#load(component_meta) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/alephant/broker/load_strategy/revalidate/strategy.rb', line 17

def load(component_meta)
  loaded_content = cached_object(component_meta)

  update_content(component_meta) if loaded_content.expired?

  data = loaded_content.to_h
  data.fetch(:meta, {})[:status] = 200
  add_revalidating_headers(data) if loaded_content.expired?

  data
rescue *STORAGE_ERRORS
  update_content(component_meta)

  {
    content:      '',
    content_type: 'text/html',
    meta:         { status: 202 }
  }
end