class Shellac::Cache

Constants

VARNISH_CONFIGURATION

Public Instance Methods

client() click to toggle source

return client instance

# File lib/shellac/cache.rb, line 12
def client
  @client ||= Varnish::Client.new   "#{config("host")}:#{config("port")}",
                                    :timeout => config("timeout"),
                                    :keep_alive => config("keep_alive")
end
purge(path, recursive) click to toggle source

purge a regular expression of url

# File lib/shellac/cache.rb, line 19
def purge path, recursive
  
  if recursive
    regex = "^#{path}" # purge any page starting with regex
  else
    regex = "^#{path}$"
  end
  
  # write to log
  Rails.logger.info "*** Purging#{" (recursively)" if recursive}: #{path}"
  
  # purge with
  client.purge "req.http.host ~ ^#{config("host")} && req.url ~ #{regex}"
end

Protected Instance Methods

config(attr) click to toggle source
# File lib/shellac/cache.rb, line 36
def config attr
  begin
    VARNISH_CONFIGURATION[attr]
  rescue
    raise "Shellac was not properly configured for #{::Rails.env} environment. Did you run rails generate shellac:install?"
  end
end