Put adds the provided (sessionKey, cs) pair to the cache. If cs is nil, the entry corresponding to sessionKey is removed from the cache instead.
(sessionKey string, cs *ClientSessionState)
| 1665 | // Put adds the provided (sessionKey, cs) pair to the cache. If cs is nil, the entry |
| 1666 | // corresponding to sessionKey is removed from the cache instead. |
| 1667 | func (c *lruSessionCache) Put(sessionKey string, cs *ClientSessionState) { |
| 1668 | c.Lock() |
| 1669 | defer c.Unlock() |
| 1670 | |
| 1671 | if elem, ok := c.m[sessionKey]; ok { |
| 1672 | if cs == nil { |
| 1673 | c.q.Remove(elem) |
| 1674 | delete(c.m, sessionKey) |
| 1675 | } else { |
| 1676 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1677 | entry.state = cs |
| 1678 | c.q.MoveToFront(elem) |
| 1679 | } |
| 1680 | return |
| 1681 | } |
| 1682 | |
| 1683 | if c.q.Len() < c.capacity { |
| 1684 | entry := &lruSessionCacheEntry{sessionKey, cs} |
| 1685 | c.m[sessionKey] = c.q.PushFront(entry) |
| 1686 | return |
| 1687 | } |
| 1688 | |
| 1689 | elem := c.q.Back() |
| 1690 | entry := elem.Value.(*lruSessionCacheEntry) |
| 1691 | delete(c.m, entry.sessionKey) |
| 1692 | entry.sessionKey = sessionKey |
| 1693 | entry.state = cs |
| 1694 | c.q.MoveToFront(elem) |
| 1695 | c.m[sessionKey] = elem |
| 1696 | } |
| 1697 | |
| 1698 | // Get returns the [ClientSessionState] value associated with a given key. It |
| 1699 | // returns (nil, false) if no value is found. |
nothing calls this directly
no outgoing calls
no test coverage detected