Fixed bugs in clearing cache