summaryrefslogtreecommitdiff
path: root/bin/fltr_cache.rc
diff options
context:
space:
mode:
authorglenda <glenda@9front.local>2020-11-15 15:13:27 +0000
committerglenda <glenda@9front.local>2020-11-15 15:13:27 +0000
commit39318169e0b50551db511851829f9337c5fa6313 (patch)
tree65a0ef5c1da9677532fa8105293d017919473057 /bin/fltr_cache.rc
Import site to git
Diffstat (limited to 'bin/fltr_cache.rc')
-rwxr-xr-xbin/fltr_cache.rc37
1 files changed, 37 insertions, 0 deletions
diff --git a/bin/fltr_cache.rc b/bin/fltr_cache.rc
new file mode 100755
index 0000000..9394724
--- /dev/null
+++ b/bin/fltr_cache.rc
@@ -0,0 +1,37 @@
+#!/bin/rc
+
+fn fltr_cache {
+ a=()
+ tmpf=()
+
+ proc=$1
+ shift
+
+ if(~ $#* 0) {
+ tmpf=/tmp/fmttmp.$pid
+ f=$tmpf
+ score=`{{tee $tmpf || exit 1} | sha1sum}
+ }
+ if not {
+ f=$1
+ if(~ $f */) {
+ score=`{du -an $f | sha1sum || exit 1} # XXX using -n(bytes) instead of -t(lastmod) because sitemap proc touches files in tree.
+ a=$f
+ f=/dev/null
+ }
+ if not {
+ score=`{sha1sum $f || exit 1}
+ score=$score(1)
+ }
+ }
+ cachedir=/tmp/fltr_cache/$score
+ mkdir -p $cachedir >[2]/dev/null
+
+ if(test -s $cachedir/$proc)
+ cat $cachedir/$proc
+ if not
+ if($proc $a < $f | tee $cachedir/$pid)
+ mv $cachedir/$pid $cachedir/$proc
+
+ rm $tmpf $cachedir/$pid >[2]/dev/null &
+}