GetAndRefresh retrieves the auth ID bound to a session and refreshes TTL on hit. This extends the binding lifetime for active sessions.
(sessionID string)
| 58 | // GetAndRefresh retrieves the auth ID bound to a session and refreshes TTL on hit. |
| 59 | // This extends the binding lifetime for active sessions. |
| 60 | func (c *SessionCache) GetAndRefresh(sessionID string) (string, bool) { |
| 61 | if sessionID == "" { |
| 62 | return "", false |
| 63 | } |
| 64 | now := time.Now() |
| 65 | c.mu.Lock() |
| 66 | entry, ok := c.entries[sessionID] |
| 67 | if !ok { |
| 68 | c.mu.Unlock() |
| 69 | return "", false |
| 70 | } |
| 71 | if now.After(entry.expiresAt) { |
| 72 | delete(c.entries, sessionID) |
| 73 | c.mu.Unlock() |
| 74 | return "", false |
| 75 | } |
| 76 | // Refresh TTL on successful access |
| 77 | entry.expiresAt = now.Add(c.ttl) |
| 78 | c.entries[sessionID] = entry |
| 79 | c.mu.Unlock() |
| 80 | return entry.authID, true |
| 81 | } |
| 82 | |
| 83 | // Set binds a session to an auth ID with TTL refresh. |
| 84 | func (c *SessionCache) Set(sessionID, authID string) { |
no outgoing calls