Class: PagesCore::StaticCache::VarnishHandler
- Inherits:
-
Object
- Object
- PagesCore::StaticCache::VarnishHandler
- Defined in:
- lib/pages_core/static_cache/varnish_handler.rb
Instance Attribute Summary collapse
-
#varnish_url ⇒ Object
readonly
Returns the value of attribute varnish_url.
Instance Method Summary collapse
- #cache_page(_controller, request, response) ⇒ Object
- #cache_page_permanently(controller, request, response) ⇒ Object
-
#initialize(varnish_url) ⇒ VarnishHandler
constructor
A new instance of VarnishHandler.
- #purge! ⇒ Object
- #sweep! ⇒ Object
- #sweep_now! ⇒ Object
Constructor Details
#initialize(varnish_url) ⇒ VarnishHandler
Returns a new instance of VarnishHandler.
10 11 12 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 10 def initialize(varnish_url) @varnish_url = varnish_url end |
Instance Attribute Details
#varnish_url ⇒ Object (readonly)
Returns the value of attribute varnish_url.
8 9 10 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 8 def varnish_url @varnish_url end |
Instance Method Details
#cache_page(_controller, request, response) ⇒ Object
14 15 16 17 18 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 14 def cache_page(_controller, request, response) response.set_header("X-Cache-Tags", "static") request.[:skip] = true # controller.expires_in 1.hour, public: true end |
#cache_page_permanently(controller, request, response) ⇒ Object
20 21 22 23 24 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 20 def cache_page_permanently(controller, request, response) response.set_header("X-Cache-Tags", "permanent") request.[:skip] = true controller.expires_in 1.year, public: true end |
#purge! ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 26 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
35 36 37 38 39 40 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 35 def sweep! return unless PagesCore::CacheSweeper.enabled # PagesCore::SweepCacheJob.perform_later sweep_now! end |
#sweep_now! ⇒ Object
42 43 44 45 46 |
# File 'lib/pages_core/static_cache/varnish_handler.rb', line 42 def sweep_now! return unless PagesCore::CacheSweeper.enabled ban_request("static").run end |