Add adds a Client to the manager. You can use this to individually configure Clients in the manager.
(client *Client)
| 61 | // Add adds a Client to the manager. You can use this to individually configure |
| 62 | // Clients in the manager. |
| 63 | func (m *ClientManager) Add(client *Client) { |
| 64 | m.initInternals() |
| 65 | m.mu.Lock() |
| 66 | defer m.mu.Unlock() |
| 67 | |
| 68 | key := cacheKey(client.Certificate) |
| 69 | now := time.Now() |
| 70 | if ele, hit := m.cache[key]; hit { |
| 71 | item := ele.Value.(*managerItem) |
| 72 | item.client = client |
| 73 | item.lastUsed = now |
| 74 | m.ll.MoveToFront(ele) |
| 75 | return |
| 76 | } |
| 77 | ele := m.ll.PushFront(&managerItem{key, client, now}) |
| 78 | m.cache[key] = ele |
| 79 | if m.MaxSize != 0 && m.ll.Len() > m.MaxSize { |
| 80 | m.mu.Unlock() |
| 81 | m.removeOldest() |
| 82 | m.mu.Lock() |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | // Get gets a Client from the manager. If a Client is not found in the manager |
| 87 | // or if a Client has remained in the manager longer than MaxAge, Get will call |