From: Ian Jackson Date: Mon, 28 Jun 2010 01:15:32 +0000 (+0100) Subject: cache pngs X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=7602370042dc4665a9000aa88dd24a6ae4f3c2c6;p=rrd-graphs.git cache pngs --- diff --git a/cgi b/cgi index d6193ad..c348508 100755 --- a/cgi +++ b/cgi @@ -253,27 +253,34 @@ if (defined $elem) { my $sloth= param('sloth'); die unless defined $sloth; $sloth =~ m/^(\d+)$/ or die; + $sloth= $1+0; my $end= $g->{TimeRanges}[$sloth]; - die unless defined $end; + + my $cacheid= "$section!$group!$elem!$sloth!$width!$height"; + my $cachepath= "cache/$cacheid.png"; my @args= @{ $g->{Args} }; s,\, $end/$1 ,ge foreach @args; unshift @args, qw(--end now --start), "end-${end}s"; - if (param('debug')) { - print((join "\n",@args),"\n"); exit 0; - } - print "Content-Type: image/png\n\n"; - my $title= $group; if (length $elem) { $title.= " $elem"; } $title .= " $g->{Units}" if $g->{Units}; - unshift @args, '-t', $title; + unshift @args, '-t', $title, '-w',$width, '-h',$height; + unshift @args, qw(-a PNG --full-size-mode); + + if (param('debug')) { + print((join "\n",@args),"\n"); exit 0; + } - exec (qw(rrdtool graph - -a PNG --full-size-mode), - '-w',$width, '-h',$height, - @args); +#print STDERR "||| ",(join ' ', map { "'$_'" } @args)." |||\n"; + exec(qw(sh -ec), <<'END', 'x', $cachepath, @args); + p="$1"; shift + rrdtool graph "$p" --lazy "$@" >/dev/null + printf "Content-Type: image/png\n\n" + exec cat "$p" +END die $!; }