Fugu

 view release on metacpan or  search on metacpan

lib/Fugu/Proxy.pod  view on Meta::CPAN


Nothing here knows what content is worth caching. That is a callback
on the cache, because the answer is a property of the mirror and not
of HTTP.

L<HTTP::Daemon> and L<LWP::UserAgent> load in the child, at serve
time. Thus the module keeps the core-Perl load contract of Fugu, and
an installation without them still loads it.

=head1 THE SUPERVISOR

=head2 new

C<new(%args)> creates a supervisor.

These are the arguments:

=over 4

=item C<cache>

A Fugu::Proxy::Cache. This argument is necessary.

=item C<pidfile>

A L<Fugu::Pidfile> for the child. This argument is necessary.

=item C<store>

A L<Fugu::StateFile> that holds the port. This argument is necessary.

=item C<logfile>

Where the output of the child goes. The default is F</dev/null>.

=item C<ports>

The range to look in, as [C<first>, C<last>]. The default is 8080 to
8180.

=item C<log>

The logger.

=back

=head2 start

C<start()> finds a free port, spawns the child, records its PID and
port, and waits until it takes connections. A proxy that already runs
returns its port and starts nothing.

=head2 stop

C<stop()> stops the child and forgets its port. The stop is a
C<SIGTERM> with a grace period, then a C<SIGKILL>, through
L<Fugu::Process>.

=head2 is_running

C<is_running()> reports if the child is alive. The check reaps, so a
child that became a zombie reads as stopped.

=head2 port

C<port()> returns the port the running proxy listens on.

=head2 wait_ready

C<wait_ready($timeout)> polls until the proxy takes a connection. The
default timeout is 30 seconds.

=head2 serve

C<serve($port)> runs the server loop. The spawned child calls this,
and it returns when a C<SIGTERM> arrives.

The signal handler writes one byte to a self-pipe that the select loop
watches. Thus the loop notices the signal between requests and not
inside one.

=head2 warm

C<warm()> fills the metadata table from what is already on disk. A
cold proxy would otherwise stat every file on its first hit.

=head2 cache, error

C<cache()> returns the cache object. C<error()> returns the most
recent failure.

=head1 THE CACHE

=head2 new

C<new(%args)> creates a cache.

These are the arguments:

=over 4

=item C<dir>

The cache root. This argument is necessary. The mirrored tree goes
under F<E<lt>dirE<gt>/proxy>.

=item C<cacheable>

A code reference that takes a URL and reports if it is worth keeping.
The default says no. A cache that guesses fills a home directory with
pages nobody will read again.

=item C<types>

Extra content types, as a hash reference of pattern to type.

=back

=head2 cache_path

C<cache_path($url)> maps a URL to its file:



( run in 0.936 second using v1.01-cache-2.11-cpan-14f38c9f855 )