Class: VarnishRailsService
- Inherits:
-
Object
- Object
- VarnishRailsService
- Includes:
- Singleton
- Defined in:
- lib/varnish_rails/varnish_rails_service.rb
Class Method Summary collapse
- .ban_cache(pattern) ⇒ Object
- .purge_cache(url) ⇒ Object
-
.purge_xkey_cache(*xkeys) ⇒ Object
Class Methods ========================================================.
Class Method Details
.ban_cache(pattern) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/varnish_rails/varnish_rails_service.rb', line 62 def self.ban_cache(pattern) return if !VarnishRails.configuration.enable uri = URI.parse(VarnishRails.configuration.url) http_request = Net::HTTPGenericRequest.new("BAN", false, false, uri) http_request[VarnishRails.configuration.header_x_ban_url] = pattern = { use_ssl: uri.scheme == "https" } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(http_request) end puts "Varnish - ban_cache - #{pattern}".varnish_debug_color if VarnishRails.configuration.print_requests puts response.inspect.varnish_debug_color if VarnishRails.configuration.print_requests end |
.purge_cache(url) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/varnish_rails/varnish_rails_service.rb', line 47 def self.purge_cache(url) return if !VarnishRails.configuration.enable uri = URI.parse("#{VarnishRails.configuration.url}#{url}") http_request = Net::HTTPGenericRequest.new("PURGE", false, false, uri) = { use_ssl: uri.scheme == "https" } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(http_request) end puts "Varnish - purge_cache - #{url}".varnish_debug_color if VarnishRails.configuration.print_requests puts response.inspect.varnish_debug_color if VarnishRails.configuration.print_requests end |
.purge_xkey_cache(*xkeys) ⇒ Object
Class Methods ========================================================
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/varnish_rails/varnish_rails_service.rb', line 25 def self.purge_xkey_cache(*xkeys) return if !VarnishRails.configuration.enable xkey_purge = '' xkeys.each do |xkey| xkey_purge = xkey_purge + xkey + ' ' end xkey_purge = xkey_purge.strip uri = URI.parse(VarnishRails.configuration.url) http_request = Net::HTTPGenericRequest.new("PURGE", false, false, uri) http_request[VarnishRails.configuration.header_xkey_purge] = xkey_purge = { use_ssl: uri.scheme == "https" } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(http_request) end puts "Varnish - purge_xkey_cache - #{xkey_purge}".varnish_debug_color if VarnishRails.configuration.print_requests puts response.inspect.varnish_debug_color if VarnishRails.configuration.print_requests end |