SaveWithContext saves the session data and updates the cookie, using the provided context for cancellation and timeout control. Note: If the session is being used in the handler, calling SaveWithContext will have no effect and the session will automatically be saved when the handler returns. Param
(ctx context.Context)
| 357 | // |
| 358 | // err := s.SaveWithContext(ctx) |
| 359 | func (s *Session) SaveWithContext(ctx context.Context) error { |
| 360 | ctx = backgroundIfNil(ctx) |
| 361 | |
| 362 | if s.ctx == nil { |
| 363 | return s.saveSessionWithContext(ctx) |
| 364 | } |
| 365 | |
| 366 | // If the session is being used in the handler, it should not be saved |
| 367 | if m, ok := s.ctx.Locals(middlewareContextKey).(*Middleware); ok { |
| 368 | if m.Session == s { |
| 369 | // Session is in use, so we do nothing and return |
| 370 | return nil |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return s.saveSessionWithContext(ctx) |
| 375 | } |
| 376 | |
| 377 | // saveSessionWithContext encodes session data and saves it to storage using the provided context. |
| 378 | func (s *Session) saveSessionWithContext(ctx context.Context) error { |