From: Ian Jackson Date: Wed, 7 Jul 2010 13:16:07 +0000 (+0100) Subject: remove stale caches based on MD5 of rrdtool args X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ijackson/git?p=rrd-graphs.git;a=commitdiff_plain;h=b651d58a24d618930b4b6ddcbc611eb118f12111 remove stale caches based on MD5 of rrdtool args --- diff --git a/cgi b/cgi index 5133ffb..1d29b1d 100755 --- a/cgi +++ b/cgi @@ -4,6 +4,7 @@ use strict qw(vars); use CGI::SpeedyCGI qw/:standard -no_xhtml/; use CGI qw/:standard -no_xhtml/; use POSIX; +use MD5; sub fail ($) { print(header(-status=>500), @@ -411,9 +412,6 @@ if (defined $elem) { 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"; @@ -425,6 +423,10 @@ if (defined $elem) { unshift @args, '-t', $title, '-w',$width, '-h',$height; unshift @args, qw(-a PNG --full-size-mode); + my $cacheid= "$section!$group!$elem!$sloth!$width!$height!"; + $cacheid .= unpack "H*", MD5->hash(join '\0', @args); + my $cachepath= "cache/$cacheid.png"; + if (param('debug')) { print((join "\n",@args),"\n"); exit 0; } diff --git a/cgi-invoke b/cgi-invoke index cd46ce9..8d90633 100755 --- a/cgi-invoke +++ b/cgi-invoke @@ -7,8 +7,5 @@ exec with-lock-ex -w data/graph-lock sh -ec ' rm -f cache ln -s $GRAPH_CGI_CACHE cache fi - if test cgi -nt cache/.; then - rm -f cache/* - fi - ./cgi "$@" + exec ./cgi "$@" ' x "$@"