save cache to local before page closed