Added conditional check before saving cached data.