lib/shellac/cache.rb in shellac-0.0.2.4 vs lib/shellac/cache.rb in shellac-0.0.3.rc2

- old
+ new

@@ -1,35 +1,33 @@ require 'singleton' module Shellac class Cache - include Singleton + include ::Singleton - if File.exist?("#{File.expand_path(Rails.root.to_s)}/config/varnish.yml") + if ::File.exist?("#{File.expand_path(Rails.root.to_s)}/config/varnish.yml") VARNISH_CONFIGURATION = YAML.load_file("#{Rails.root.to_s}/config/varnish.yml")[::Rails.env] end # return client instance def client - @client ||= Varnish::Client.new "#{config("host")}:#{config("port")}", + @client ||= ::Varnish::Client.new "#{config("server")}:#{config("port")}", :timeout => config("timeout"), :keep_alive => config("keep_alive") end # purge a regular expression of url - def purge path, recursive + def purge path, recursive=false, hosts=nil - if recursive - regex = "^#{path}" # purge any page starting with regex - else - regex = "^#{path}$" - end + # fall back to configuration and convert to array + hosts ||= config('hosts').delete(' ').split(',') - # write to log - Rails.logger.info "*** Purging#{" (recursively)" if recursive}: #{path}" + # purge any page starting with regex + regex = "^#{path}#{'$' unless recursive}" # purge with - client.purge "req.http.host ~ ^#{config("host")} && req.url ~ #{regex}" + client.purge "req.http.host ~ ^(#{hosts.join('|')}) && req.url ~ #{regex}" + end protected def config attr \ No newline at end of file