| 136 | } |
| 137 | |
| 138 | func (c *cache) OnUpsert(id idpool.ID, key AllocatorKey) { |
| 139 | for _, validator := range c.allocator.cacheValidators { |
| 140 | if err := validator(AllocatorChangeUpsert, id, key); err != nil { |
| 141 | c.logger.Warn( |
| 142 | "Skipping event for invalid identity", |
| 143 | logfields.Error, err, |
| 144 | logfields.Identity, id, |
| 145 | logfields.Event, AllocatorChangeUpsert, |
| 146 | ) |
| 147 | return |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | c.mutex.Lock() |
| 152 | defer c.mutex.Unlock() |
| 153 | |
| 154 | if k, ok := c.nextCache[id]; ok { |
| 155 | delete(c.nextKeyCache, k.GetKey()) |
| 156 | } |
| 157 | |
| 158 | c.nextCache[id] = key |
| 159 | if key != nil { |
| 160 | c.nextKeyCache[key.GetKey()] = id |
| 161 | } |
| 162 | |
| 163 | c.allocator.idPool.Remove(id) |
| 164 | |
| 165 | c.emitChange(AllocatorChange{Kind: AllocatorChangeUpsert, ID: id, Key: key}) |
| 166 | |
| 167 | c.sendEvent(AllocatorChangeUpsert, id, key) |
| 168 | } |
| 169 | |
| 170 | func (c *cache) OnDelete(id idpool.ID, key AllocatorKey) { |
| 171 | for _, validator := range c.allocator.cacheValidators { |