no submod
This commit is contained in:
28
work/notea/crawler/cache.sh
Normal file
28
work/notea/crawler/cache.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#! /bin/bash
|
||||
|
||||
cache() (
|
||||
path() {
|
||||
echo "$CACHE/$(echo "$*" | base64 | md5sum | awk '{print $1}')"
|
||||
}
|
||||
get() {
|
||||
local path="$(path "$*")"
|
||||
if ! [ -f "$path" ]; then
|
||||
return 1
|
||||
fi
|
||||
if wc -c "$path" | grep -q '^[ ]*0[ ]*$'; then
|
||||
return 1
|
||||
fi
|
||||
local created="$(date -r "$path" +%s)"
|
||||
local now="$(date +%s)"
|
||||
if ((now-created > CACHE_DURATION)); then
|
||||
return 1
|
||||
fi
|
||||
cat "$path"
|
||||
}
|
||||
put() {
|
||||
local path="$(path "$*")"
|
||||
tee "$path"
|
||||
}
|
||||
"$@"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user