improved cache clear helper function.