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 files
|
||||||
local file
|
local file
|
||||||
|
|
||||||
if [ -z "$ZAF_CACHE_DIR" ] || [ "$ZAF_CACHE_DIR" = "/tmp/zafc/" ]; then
|
if [ "$ZAF_CACHE_DIR" = "/tmp/zafc" ] && ! [ -d "$ZAF_CACHE_DIR" ]; then
|
||||||
ZAF_CACHE_DIR=${ZAF_TMP_DIR}/zafc
|
|
||||||
mkdir -p $ZAF_CACHE_DIR
|
mkdir -p $ZAF_CACHE_DIR
|
||||||
chown $ZAF_FILES_UID $ZAF_CACHE_DIR >/dev/null 2>/dev/null
|
chown $ZAF_FILES_UID $ZAF_CACHE_DIR >/dev/null 2>/dev/null
|
||||||
fi
|
fi
|
||||||
if [ -w $ZAF_CACHE_DIR ]; then
|
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
|
|
||||||
zaf_dbg "Cache dir $ZAF_CACHE_DIR is not accessible! Disabling cache."
|
zaf_dbg "Cache dir $ZAF_CACHE_DIR is not accessible! Disabling cache."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -27,7 +16,7 @@ zaf_cache_init(){
|
|||||||
zaf_cache_clean(){
|
zaf_cache_clean(){
|
||||||
local files
|
local files
|
||||||
|
|
||||||
if [ -n "$ZAF_CACHE_DIR" ]; then
|
if [ -w "$ZAF_CACHE_DIR" ]; then
|
||||||
zaf_wrn "Removing cache entries"
|
zaf_wrn "Removing cache entries"
|
||||||
files=$(find $ZAF_CACHE_DIR/ -type f)
|
files=$(find $ZAF_CACHE_DIR/ -type f)
|
||||||
[ -n "$files" ] && rm -f $files
|
[ -n "$files" ] && rm -f $files
|
||||||
@ -128,6 +117,7 @@ zaf_cache_delentry(){
|
|||||||
|
|
||||||
# List entries in cache
|
# List entries in cache
|
||||||
zaf_cache_list(){
|
zaf_cache_list(){
|
||||||
|
! [ -w $ZAF_CACHE_DIR ] && return 1
|
||||||
local i
|
local i
|
||||||
ls ${ZAF_CACHE_DIR}/*info >/dev/null 2>/dev/null || return 1
|
ls ${ZAF_CACHE_DIR}/*info >/dev/null 2>/dev/null || return 1
|
||||||
local key
|
local key
|
||||||
@ -139,7 +129,7 @@ zaf_cache_list(){
|
|||||||
# Get object from cache
|
# Get object from cache
|
||||||
# $1 key
|
# $1 key
|
||||||
zaf_fromcache(){
|
zaf_fromcache(){
|
||||||
! [ -r $ZAF_CACHE_DIR ] || [ -n "$ZAF_NOCACHE" ] && return 1
|
! [ -w $ZAF_CACHE_DIR ] && return 3
|
||||||
local key
|
local key
|
||||||
local value
|
local value
|
||||||
local infofile
|
local infofile
|
||||||
@ -150,13 +140,11 @@ zaf_fromcache(){
|
|||||||
infofile="${ZAF_CACHE_DIR}/${key}.info"
|
infofile="${ZAF_CACHE_DIR}/${key}.info"
|
||||||
|
|
||||||
if [ -f $datafile ]; then
|
if [ -f $datafile ]; then
|
||||||
#zaf_cache_lock $key || return 3
|
|
||||||
#zaf_cache_unlock $key
|
|
||||||
if [ "$infofile" -nt "$datafile" ]; then
|
if [ "$infofile" -nt "$datafile" ]; then
|
||||||
zaf_trc "Cache: serving $1($key) from cache"
|
zaf_trc "Cache: serving $1($key) from cache"
|
||||||
cat "$datafile" || { ls -la "$datafile" >&2; zaf_err "auuu: $1"; }
|
cat "$datafile"
|
||||||
else
|
else
|
||||||
#zaf_cache_delentry $key
|
zaf_cache_delentry $key
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -76,19 +76,15 @@ zaf_block_get_option() {
|
|||||||
zaf_ctrl_get_global_option() {
|
zaf_ctrl_get_global_option() {
|
||||||
local ctrlvar
|
local ctrlvar
|
||||||
local ctrlopt
|
local ctrlopt
|
||||||
local key
|
|
||||||
|
|
||||||
key="$1-$2"
|
ctrlopt="ZAF_CTRL_$(zaf_stripctrl $2)"
|
||||||
if ! zaf_fromcache $key; then
|
eval ctrlvar=\$$ctrlopt
|
||||||
ctrlopt="ZAF_CTRL_$(zaf_stripctrl $2)"
|
if [ -n "$ctrlvar" ]; then
|
||||||
eval ctrlvar=\$$ctrlopt
|
zaf_dbg "Overriding control field $2 from env $ctrlopt($ctrlvar)"
|
||||||
if [ -n "$ctrlvar" ]; then
|
echo $ctrlopt
|
||||||
zaf_dbg "Overriding control field $2 from env $ctrlopt($ctrlvar)"
|
else
|
||||||
echo $ctrlopt
|
zaf_ctrl_get_global_block <$1 | zaf_block_get_moption "$2" \
|
||||||
else
|
|| zaf_ctrl_get_global_block <$1 | zaf_block_get_option "$2"
|
||||||
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"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,19 +95,15 @@ zaf_ctrl_get_global_option() {
|
|||||||
zaf_ctrl_get_item_option() {
|
zaf_ctrl_get_item_option() {
|
||||||
local ctrlvar
|
local ctrlvar
|
||||||
local ctrlopt
|
local ctrlopt
|
||||||
local key
|
|
||||||
|
|
||||||
key="i$1-$2-$3"
|
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
||||||
if ! zaf_fromcache "$key"; then
|
eval ctrlvar=\$$ctrlopt
|
||||||
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
if [ -n "$ctrlvar" ]; then
|
||||||
eval ctrlvar=\$$ctrlopt
|
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
||||||
if [ -n "$ctrlvar" ]; then
|
echo $ctrlopt
|
||||||
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
else
|
||||||
echo $ctrlopt
|
zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_moption "$3" \
|
||||||
else
|
|| zaf_ctrl_get_item_block <$1 "$2" | zaf_block_get_option "$3"
|
||||||
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"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,19 +114,15 @@ zaf_ctrl_get_item_option() {
|
|||||||
zaf_ctrl_get_extitem_option() {
|
zaf_ctrl_get_extitem_option() {
|
||||||
local ctrlvar
|
local ctrlvar
|
||||||
local ctrlopt
|
local ctrlopt
|
||||||
local key
|
|
||||||
|
|
||||||
key="e$1-$2-$3"
|
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
||||||
if ! zaf_fromcache "$key"; then
|
eval ctrlvar=\$$ctrlopt
|
||||||
ctrlopt="ZAF_CTRLI_$(zaf_stripctrl $2)_$(zaf_stripctrl $3)"
|
if [ -n "$ctrlvar" ]; then
|
||||||
eval ctrlvar=\$$ctrlopt
|
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
||||||
if [ -n "$ctrlvar" ]; then
|
echo $ctrlopt
|
||||||
zaf_dbg "Overriding item control field $2/$3 from env $ctrlopt($ctrlvar)"
|
else
|
||||||
echo $ctrlopt
|
zaf_ctrl_get_extitem_block <$1 "$2" | zaf_block_get_moption "$3" \
|
||||||
else
|
|| zaf_ctrl_get_extitem_block <$1 "$2" | zaf_block_get_option "$3"
|
||||||
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"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
zaf
3
zaf
@ -97,6 +97,9 @@ agent-config)
|
|||||||
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
server-config)
|
||||||
|
zaf_wrn "Not implemented yet"
|
||||||
|
;;
|
||||||
|
|
||||||
###### Plugins related commands
|
###### Plugins related commands
|
||||||
update)
|
update)
|
||||||
|
Loading…
Reference in New Issue
Block a user