Simplify cache management, and cleanup code

Signed-off-by: Christophe Chapuis <chris.chapuis@gmail.com>