When to Reset Your Keys: Optimal Timing of Security Updates via Learning