Class: Shellac::Cache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shellac/cache.rb

Constant Summary collapse

VARNISH_CONFIGURATION =
YAML.load_file("#{Rails.root.to_s}/config/varnish.yml")[::Rails.env]

Instance Method Summary collapse

Instance Method Details

#clientObject

return client instance



12
13
14
15
16
# 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) ⇒ Object

purge a regular expression of url



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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