Class: PagesCore::StaticCache::VarnishHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pages_core/static_cache/varnish_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(varnish_url) ⇒ VarnishHandler

Returns a new instance of VarnishHandler.



8
9
10
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 8

def initialize(varnish_url)
  @varnish_url = varnish_url
end

Instance Attribute Details

#varnish_urlObject (readonly)

Returns the value of attribute varnish_url.



6
7
8
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 6

def varnish_url
  @varnish_url
end

Instance Method Details

#cache_page(_controller, request, response) ⇒ Object



12
13
14
15
16
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 12

def cache_page(_controller, request, response)
  response.set_header("X-Cache-Tags", "static")
  request.session_options[:skip] = true
  # controller.expires_in 1.hour, public: true
end

#cache_page_permanently(controller, request, response) ⇒ Object



18
19
20
21
22
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 18

def cache_page_permanently(controller, request, response)
  response.set_header("X-Cache-Tags", "permanent")
  request.session_options[:skip] = true
  controller.expires_in 1.year, public: true
end

#purge!Object



24
25
26
27
28
29
30
31
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 24

def purge!
  return unless PagesCore::CacheSweeper.enabled

  hydra = Typhoeus::Hydra.hydra
  hydra.queue(ban_request("static"))
  hydra.queue(ban_request("permanent"))
  hydra.run
end

#sweep!Object



33
34
35
36
37
38
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 33

def sweep!
  return unless PagesCore::CacheSweeper.enabled

  # PagesCore::SweepCacheJob.perform_later
  sweep_now!
end

#sweep_now!Object



40
41
42
43
44
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 40

def sweep_now!
  return unless PagesCore::CacheSweeper.enabled

  ban_request("static").run
end