Sha256: e58d1a87f85cb003e5995289cf15f2ee2b660c5eaafbf48f35aeed80819aedc5

Contents?: true

Size: 960 Bytes

Versions: 1

Compression:

Stored size: 960 Bytes

Contents

module Shellac
  class Cache
    include Singleton
    
    VARNISH_CONFIGURATION = YAML.load_file("#{Rails.root.to_s}/config/varnish.yml")[::Rails.env]    
    
    # return client instance
    def client
      @client ||= Varnish::Client.new  "#{config("host")}:#{config("port")}",
                                :timeout => config("timeout"),
                                :keep_alive => config("keep_alive")
    end
    
    # purge a regular expression of url
    def purge path, recursive=false
      
      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
    
      def config attr
        VARNISH_CONFIGURATION[attr]
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shellac-0.0.1 lib/shellac/cache.rb