MCPcopy
hub / github.com/sideshow/apns2 / Add

Method Add

client_manager.go:63–84  ·  view source on GitHub ↗

Add adds a Client to the manager. You can use this to individually configure Clients in the manager.

(client *Client)

Source from the content-addressed store, hash-verified

61// Add adds a Client to the manager. You can use this to individually configure
62// Clients in the manager.
63func (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

Callers 6

TestClientManagerAddFunction · 0.95
GetMethod · 0.95
TestExpiresBeforeAnHourFunction · 0.80

Calls 4

initInternalsMethod · 0.95
removeOldestMethod · 0.95
cacheKeyFunction · 0.85
LenMethod · 0.80