fltr_cache.rc - swerc - anselm's simpler werc fork
(HTM) git clone git://git.suckless.org/swerc
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
fltr_cache.rc (826B)
---
1 #!/usr/bin/env rc
2
3 fn fltr_cache {
4 a=()
5 tmpf=()
6
7 proc=$1
8 shift
9
10 if(~ $#* 0) {
11 tmpf=/tmp/fmttmp.$pid
12 f=$tmpf
13 score=`{{tee $tmpf || exit 1} | sha1sum}
14 }
15 if not {
16 f=$1
17 if(~ $f */) {
18 score=`{du -an $f | sha1sum || exit 1} # XXX using -n(bytes) instead of -t(lastmod) because sitemap proc touches files in tree.
19 a=$f
20 f=/dev/null
21 }
22 if not {
23 score=`{sha1sum $f || exit 1}
24 score=$score(1)
25 }
26 }
27 cachedir=/tmp/fltr_cache/$score
28 mkdir -p $cachedir >[2]/dev/null
29
30 if(test -s $cachedir/$proc)
31 cat $cachedir/$proc
32 if not
33 if($proc $a < $f | tee $cachedir/$pid)
34 mv $cachedir/$pid $cachedir/$proc
35
36 rm $tmpf $cachedir/$pid >[2]/dev/null &
37 }