gitweb/lib - capture output directly to cache entry file
This commit makes it possible to capture output redirecting STDOUT to
cache entry file; this way we don't need to store whole output in
memory in order to cache it.
The ->capture() method in GitwebCache::Capture::Simple is extended so
it signature is now ->capture($code[, $to]). This means that it
accepts optional $to parameter, which specifies either filehandle open
for writing, or a file name, which would be used to capture output
instead of in-memory file. The ->capture_start() and ->capture_stop()
methods that are used by ->capture() also got updated.
GitwebCache::SimpleFileCache acquired new ->compute_fh($key, $code_fh)
method. Instead of passing and returning data like ->compute(), it
passes and returns filehandles and filenames. While $code parameter
in ->compute($key, $code) call is expected to generate and return data
to be cached, the $code_fh parameter in ->compute_fh($key, $code_fh)
call is expected to print generated data to filehandle provided as its
parameter. Instead of returning data (either from cache or generated)
like ->compute(), the new ->compute_fh() method returns filehandle and
filename to read data from.
The cache_output subroutine in GitwebCache::CacheOutput now uses
->compute_fh method if cache supports it. The contents of file that
is returned by ->compute_fh is dumped to STDOUT using File::Copy::copy.
Note that ->compute_fh interface is non-standard, and is not supported
by any caching module known to author. Closest to it is ->handle($key)
method in the Cache[1] interface (proxied to ->entry($key)->handle()).
[1]: http://p3rl.org/Cache
Added tests for capturing to file in t9503, and of ->compute_fh method
in t9504.
Inspired-by-idea-by: John 'Warthog9' Hawley <warthog9@kernel.org>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>