gitweb/lib - Cache captured output (using get/set)
commit7647e2a25112a9d84a0dc0c0f02a9f95ef5c7727
authorJakub Narebski <jnareb@gmail.com>
Sun, 5 Dec 2010 20:48:51 +0000 (5 21:48 +0100)
committerJakub Narebski <jnareb@gmail.com>
Sun, 5 Dec 2010 20:48:51 +0000 (5 21:48 +0100)
tree607bdcd77bc9bc8798dbf0eae001e247a74e6c6f
parent0f9570775f808a18d834a225d785aeea6bebf10c
gitweb/lib - Cache captured output (using get/set)

Add GitwebCache::CacheOutput package, which contains cache_output
subroutine.  The cache_output gets data from cache and prints it, or
captures output of provided subroutine (code reference), saves it to
cache and prints it.  It currently uses Cache::Cache compatibile (get,
set) interface to cache.  The capture_stop currently simply runs
$capture->capture_stop().

Capturing output is done using GitwebCache::Capture::Simple compatibile
capture (->new(), ->capture($code)) passed as one of parameters; the
default solution is to use GitwebCache::Capture::Simple.

Gitweb would use cache_output to get page from cache, or to generate
page and save it to cache.  The capture_stop would be used in die_error
subroutine, because error pages would not be cached.

It is assumed that data is saved to cache _converted_, and should
therefore be read from cache and printed to STDOUT in ':raw' (binary)
mode.

Add t9505/test_cache_output.pl test, run as external test in
t9505-gitweb-cache.  It checks that cache_output behaves correctly,
namely that it saves and restores action output in cache, and that it
prints generated output or cached output, depending on whether there
exist data in cache.  This test requires Capture::Tiny to be installed
(because GitwebCache::Capture::Simple dosn't support recursive
capturing).

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
gitweb/lib/GitwebCache/CacheOutput.pm [new file with mode: 0644]
t/t9505-gitweb-cache.sh [new file with mode: 0755]
t/t9505/test_cache_output.pl [new file with mode: 0755]