Module: ESI::Invalidator

Defined in:
lib/esi/invalidator.rb

Class Method Summary collapse

Class Method Details

.start(cache) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/esi/invalidator.rb', line 14

def self.start( cache )
  Thread.new( cache ) do|cache|
    s = WEBrick::HTTPServer.new( :Port => 4001 )

    s.mount_proc("/invalidate"){|req, res|
      res.body = "<html>invalidate posted objects</html>"
      res['Content-Type'] = "text/html"
    }

    s.mount_proc("/status"){|req, res|
      res.body = "<html><body><h1>Cached objects</h1>"
      res.body << "<ul>"
      cache.keys do|key,data|
        res.body << "<li>#{key}</li>"
      end
      res.body << "</ul>"
      res.body << "</body>"
      res.body << "</html>"
      res['Content-Type'] = "text/html"
    }

    # XXX: this doesn't chain so ends up removing the mongrel trap locking the server up
    #trap("INT"){ s.shutdown }
    s.start
  end
end