chiark / gitweb /
remove stale caches based on MD5 of rrdtool args
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 7 Jul 2010 13:16:07 +0000 (14:16 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 7 Jul 2010 13:16:07 +0000 (14:16 +0100)
cgi
cgi-invoke

diff --git a/cgi b/cgi
index 5133ffb9d5f36708fd32b447e83c8002b22844f2..1d29b1d91a7e64fb6f6ce079b899e7305dc79249 100755 (executable)
--- 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,\<interval/(\d+)\>, $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;
     }
index cd46ce970978a8569630ae3f1d89ad66d513f77b..8d90633b8c2abf7e4288272ae591ada3a153e3b5 100755 (executable)
@@ -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 "$@"