doenst write cache if some error happens, make safely

Signed-off-by: Thiago Rondon <thiago.rondon@gmail.com>