mirror of
https://github.com/limosek/zaf.git
synced 2024-11-21 18:09:06 +01:00
Simplified caching
This commit is contained in:
parent
407fb2f77f
commit
3e2f1502d1
@ -4,22 +4,11 @@ zaf_cache_init(){
|
||||
local files
|
||||
local file
|
||||
|
||||
if [ -z "$ZAF_CACHE_DIR" ] || [ "$ZAF_CACHE_DIR" = "/tmp/zafc/" ]; then
|
||||
ZAF_CACHE_DIR=${ZAF_TMP_DIR}/zafc
|
||||
if [ "$ZAF_CACHE_DIR" = "/tmp/zafc" ] && ! [ -d "$ZAF_CACHE_DIR" ]; then
|
||||
mkdir -p $ZAF_CACHE_DIR
|
||||
chown $ZAF_FILES_UID $ZAF_CACHE_DIR >/dev/null 2>/dev/null
|
||||
fi
|
||||
if [ -w $ZAF_CACHE_DIR ]; then
|
||||
zaf_trc "Cache: Removing stale entries"
|
||||
files=$(find $ZAF_CACHE_DIR/ -type f -name '*.lock' -mmin +1)
|
||||
[ -n "$files" ] && rm -f $files
|
||||
(cd $ZAF_CACHE_DIR && find ./ -type f -name '*.info' -mmin +1 2>/dev/null | \
|
||||
while read line ; do
|
||||
file=$(basename $line .info)
|
||||
[ "$line" -nt "$file" ] && { rm ${file}*; zaf_trc "rm ${file}*"; }
|
||||
done
|
||||
)
|
||||
else
|
||||
if ! [ -w $ZAF_CACHE_DIR ]; then
|
||||
zaf_dbg "Cache dir $ZAF_CACHE_DIR is not accessible! Disabling cache."
|
||||
fi
|
||||
}
|
||||
@ -27,7 +16,7 @@ zaf_cache_init(){
|
||||
zaf_cache_clean(){
|
||||
local files
|
||||
|
||||
if [ -n "$ZAF_CACHE_DIR" ]; then
|
||||
if [ -w "$ZAF_CACHE_DIR" ]; then
|
||||
zaf_wrn "Removing cache entries"
|
||||
files=$(find $ZAF_CACHE_DIR/ -type f)
|
||||
[ -n "$files" ] && rm -f $files
|
||||
@ -128,6 +117,7 @@ zaf_cache_delentry(){
|
||||
|
||||
# List entries in cache
|
||||
zaf_cache_list(){
|
||||
! [ -w $ZAF_CACHE_DIR ] && return 1
|
||||
local i
|
||||
ls ${ZAF_CACHE_DIR}/*info >/dev/null 2>/dev/null || return 1
|
||||
local key
|
||||
@ -139,7 +129,7 @@ zaf_cache_list(){
|
||||
# Get object from cache
|
||||
# $1 key
|
||||
zaf_fromcache(){
|
||||
! [ -r $ZAF_CACHE_DIR ] || [ -n "$ZAF_NOCACHE" ] && return 1
|
||||
! [ -w $ZAF_CACHE_DIR ] && return 3
|
||||
local key
|
||||
local value
|
||||
local infofile
|
||||
@ -150,13 +140,11 @@ zaf_fromcache(){
|
||||
infofile="${ZAF_CACHE_DIR}/${key}.info"
|
||||
|
||||
if [ -f $datafile ]; then
|
||||
#zaf_cache_lock $key || return 3
|
||||
#zaf_cache_unlock $key
|
||||
if [ "$infofile" -nt "$datafile" ]; then
|
||||
zaf_trc "Cache: serving $1($key) from cache"
|
||||
cat "$datafile" || { ls -la "$datafile" >&2; zaf_err "auuu: $1"; }
|
||||
cat "$datafile"
|
||||
else
|
||||
#zaf_cache_delentry $key
|
||||
zaf_cache_delentry $key
|
||||
return 2
|
||||
fi
|
||||
else
|
||||
|
@ -76,19 +76,15 @@ zaf_block_get_option() {
|
||||
zaf_ctrl_get_global_option() {
|
||||
local ctrlvar
|
||||
local ctrlopt
|
||||
local key
|
||||
|
||||
key="$1-$2"
|
||||
if ! zaf_fromcache $key; then
|
||||
ctrlopt="ZAF_CTRL_$(zaf_stripctrl $2)"
|
||||
eval ctrlvar=\$$ctrlopt
|
||||
if [ -n "$ctrlvar" ]; then
|
||||
zaf_dbg "Overriding control field $2 from env $ctrlopt($ctrlvar)"
|
||||
echo $ctrlopt
|
||||
else
|
||||
zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" \
|
||||
|| zaf_ctrl_get_global_block <$1 | zaf_block_get_option "$2"
|
||||
fi | zaf_tocache_stdin "$key" "600"
|
||||
|
||||
ctrlopt="ZAF_CTRL_$(zaf_stripctrl $2)"
|
||||
eval ctrlvar=\$$ctrlopt
|
||||
if [ -n "$ctrlvar" ]; then
|
||||
zaf_dbg "Overriding control field $2 from env $ctrlopt($ctrlvar)"
|
||||
echo $ctrlopt
|
||||
else
|
||||
zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" \
|
||||
|| zaf_ctrl_get_global_block <$1 | zaf_block_get_option "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -99,19 +95,15 @@ zaf_ctrl_get_global_option() {
|
||||
zaf_ctrl_get_item_option() {
|
||||
local ctrlvar
|
||||
local ctrlopt
|
||||
local key
|
||||
|
||||
key="i$1-$2-$3"
|
||||
if ! zaf_fromcache "$key"; then
|
||||
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
||||
eval ctrlvar=\$$ctrlopt
|
||||
if [ -n "$ctrlvar" ]; then
|
||||
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
||||
echo $ctrlopt
|
||||
else
|
||||
zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" \
|
||||
|| zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_option "$3"
|
||||
fi | zaf_tocache_stdin "$key" "600"
|
||||
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
||||
eval ctrlvar=\$$ctrlopt
|
||||
if [ -n "$ctrlvar" ]; then
|
||||
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
||||
echo $ctrlopt
|
||||
else
|
||||
zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" \
|
||||
|| zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_option "$3"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -122,19 +114,15 @@ zaf_ctrl_get_item_option() {
|
||||
zaf_ctrl_get_extitem_option() {
|
||||
local ctrlvar
|
||||
local ctrlopt
|
||||
local key
|
||||
|
||||
key="e$1-$2-$3"
|
||||
if ! zaf_fromcache "$key"; then
|
||||
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
||||
eval ctrlvar=\$$ctrlopt
|
||||
if [ -n "$ctrlvar" ]; then
|
||||
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
||||
echo $ctrlopt
|
||||
else
|
||||
zaf_ctrl_get_extitem_block <$1 "$2" | zaf_block_get_moption "$3" \
|
||||
|| zaf_ctrl_get_extitem_block <$1 "$2" | zaf_block_get_option "$3"
|
||||
fi | zaf_tocache_stdin "$key" "600"
|
||||
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
||||
eval ctrlvar=\$$ctrlopt
|
||||
if [ -n "$ctrlvar" ]; then
|
||||
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
||||
echo $ctrlopt
|
||||
else
|
||||
zaf_ctrl_get_extitem_block <$1 "$2" | zaf_block_get_moption "$3" \
|
||||
|| zaf_ctrl_get_extitem_block <$1 "$2" | zaf_block_get_option "$3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user