move some functions to utils
add cache size management