MCPcopy Create free account
hub / github.com/XTLS/Go / Put

Method Put

common.go:1415–1444  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1413// Put adds the provided (sessionKey, cs) pair to the cache. If cs is nil, the entry
1414// corresponding to sessionKey is removed from the cache instead.
1415func (c *lruSessionCache) Put(sessionKey string, cs *ClientSessionState) {
1416 c.Lock()
1417 defer c.Unlock()
1418
1419 if elem, ok := c.m[sessionKey]; ok {
1420 if cs == nil {
1421 c.q.Remove(elem)
1422 delete(c.m, sessionKey)
1423 } else {
1424 entry := elem.Value.(*lruSessionCacheEntry)
1425 entry.state = cs
1426 c.q.MoveToFront(elem)
1427 }
1428 return
1429 }
1430
1431 if c.q.Len() < c.capacity {
1432 entry := &lruSessionCacheEntry{sessionKey, cs}
1433 c.m[sessionKey] = c.q.PushFront(entry)
1434 return
1435 }
1436
1437 elem := c.q.Back()
1438 entry := elem.Value.(*lruSessionCacheEntry)
1439 delete(c.m, entry.sessionKey)
1440 entry.sessionKey = sessionKey
1441 entry.state = cs
1442 c.q.MoveToFront(elem)
1443 c.m[sessionKey] = elem
1444}
1445
1446// Get returns the ClientSessionState value associated with a given key. It
1447// returns (nil, false) if no value is found.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected