@main[][sDir;sName;hf;hf2;tList;i;k;v;iSizeBefore;iSizeAfter] $sDir[174] $sName[data] # remove previous files first $tList[^file:list[$sDir]] ^tList.menu{ ^file:delete[$sDir/$tList.name] } # open hashfiles $hf[^hashfile::open[$sDir/$sName]] $hf2[^hashfile::open[$sDir/${sName}2]] ^try-catch{ ^hashfile::open[$sDir/$sName] } # check hashfile files -- it mustn't exist because of delayed opened ^checkFiles[$sDir;$sName] ^checkFiles[$sDir;${sName}2] # $hf2 for checking .cleanup[] ^fill[$hf2] $iSizeBefore(^getFileSize[$sDir;${sName}2]) $hf.temp[temp] ^hf.clear[] # add item with key '0' for 2 sec $hf.0[ $.value[zigi] $.expires(2/24/60/60) ] # add more items to hf ^for[i](1;9){ $hf.[$i][=$i=] } ^json:string[^hf.hash[]]
^checkFiles[$sDir;$sName] ^checkFiles[$sDir;${sName}2]
^$hf.0: '$hf.0'
# wait till some items expire ^sleep(3)
# $hf2 for checking .cleanup[]: add many items, read _file_ size, wait till items expire, .cleanup[], # add the same number of items, read file size again and compare sizes. # second file size must not be higher because of space used with expired items must be reused ^hf2.cleanup[] #^hf2.foreach[;]{} ^fill[$hf2] $iSizeAfter(^getFileSize[$sDir;${sName}2]) ^if($iSizeAfter > $iSizeBefore){file size increased}{file size wasn't increased}
^$hf.0: '$hf.0'

keys: ^hf.foreach[k;]{$k}[, ]
^hf.delete[1] ^hf.foreach[k;v]{^$hf.${k}: '$v'
}
^hf.delete[2] $s[^hf.foreach[k;v]{^$hf.${k}: '$v'}[
]] $s

# delete hashfile ^hf.delete[] # files mustn't exist after .delete[] ^checkFiles[$sDir;$sName]
# trying to read not existing hashfile (it must auto opened) ^hf.foreach[k;v]{^$hf.${k}: '$v'
} # files must exist now ^checkFiles[$sDir;$sName] @checkFiles[sDir;sName] ^checkFile[$sDir/${sName}.dir] ^checkFile[$sDir/${sName}.pag] @checkFile[sFileName] $sFileName -- ^if(-f $sFileName){exist}{not exist}
@getFileSize[sDir;sName][fStat] $fStat[^file::stat[$sDir/${sName}.pag]] $result($fStat.size) @fill[hf][iCount;i] $iCount(150) ^for[i](0;$iCount){ $hf.[^math:uuid[]][ $.value[^math:uuid[]] $.expires(2/24/60/60) ] } ^hf.release[]