Get retrieves the auth ID bound to a session, if still valid. Does NOT refresh the TTL on access.
(sessionID string)
| 37 | // Get retrieves the auth ID bound to a session, if still valid. |
| 38 | // Does NOT refresh the TTL on access. |
| 39 | func (c *SessionCache) Get(sessionID string) (string, bool) { |
| 40 | if sessionID == "" { |
| 41 | return "", false |
| 42 | } |
| 43 | c.mu.RLock() |
| 44 | entry, ok := c.entries[sessionID] |
| 45 | c.mu.RUnlock() |
| 46 | if !ok { |
| 47 | return "", false |
| 48 | } |
| 49 | if time.Now().After(entry.expiresAt) { |
| 50 | c.mu.Lock() |
| 51 | delete(c.entries, sessionID) |
| 52 | c.mu.Unlock() |
| 53 | return "", false |
| 54 | } |
| 55 | return entry.authID, true |
| 56 | } |
| 57 | |
| 58 | // GetAndRefresh retrieves the auth ID bound to a session and refreshes TTL on hit. |
| 59 | // This extends the binding lifetime for active sessions. |
no outgoing calls