-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcache.sh
45 lines (44 loc) · 989 Bytes
/
cache.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
## cache
## - simple lazy caching
## version 0.0.2 - allow cache dir override
##################################################
shopt -s expand_aliases # enable alias expansion
alias cache-generic-payload='
{
cache "${cache}/${FUNCNAME}" "${FUNCNAME}-payload"
}
'
##################################################
test "${cache}" || {
cache="$( dirname ${0} )/cache"
}
cache() { { local candidate_key ; candidate_key="${1}" ; local function_name ; function_name="${2}" ; }
{
test -f "${candidate_key}" || {
${function_name} > ${candidate_key}
}
cat ${candidate_key}
}
}
##################################################
if [ ! ]
then
test -d "${cache}" || {
{
echo creating cache folder ...
mkdir -v ${cache}
} 1>&2
}
else
exit 1 # wrong args
fi
##################################################
_() {
echo Created $( date )
}
cache \
"${cache}/cache-test" \
"_" \
&>/dev/null
##################################################