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.
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_url ⇒ Object (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.[: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.[: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 |