key_cacher.go
func (mkc *memoryKeyCacher) Add(keyID string, downloadedKeys []jose.JSONWebKey) (*jose.JSONWebKey, error) {
	var addingKey jose.JSONWebKey

	for _, key := range downloadedKeys {
		if key.KeyID == keyID {
			addingKey = key
		}
		if mkc.maxCacheSize == -1 {
			mkc.entries[key.KeyID] = keyCacherEntry{
				addedAt:    time.Now(),
				JSONWebKey: key,
			}
		}
	}
	if addingKey.Key != nil {
		if mkc.maxCacheSize != -1 {
			mkc.entries[addingKey.KeyID] = keyCacherEntry{
				addedAt:    time.Now(),
				JSONWebKey: addingKey,
			}
			mkc.handleOverflow()
		}
		return &addingKey, nil
	}
	return nil, ErrNoKeyFound
}
func (mkc *memoryKeyCacher) Add(keyID string, downloadedKeys []jose.JSONWebKey) (*jose.JSONWebKey, error) {
	var addingKey jose.JSONWebKey

	for _, key := range downloadedKeys {
		if key.KeyID == keyID {
			addingKey = key
		}
		if mkc.maxCacheSize == -1 {
			mkc.entries[key.KeyID] = keyCacherEntry{
				addedAt:    time.Now(),
				JSONWebKey: key,
			}
		}
	}
	if addingKey.Key != nil {
		if mkc.maxCacheSize != -1 {
			mkc.entries[addingKey.KeyID] = keyCacherEntry{
				addedAt:    time.Now(),
				JSONWebKey: addingKey,
			}
			mkc.handleOverflow()
		}
		return &addingKey, nil
	}
	return nil, ErrNoKeyFound
}
func ( mkc * memoryKeyCacher ) Add ( keyID string , downloadedKeys [ ] jose . JSONWebKey ) ( * jose . JSONWebKey , error ) { var addingKey jose . JSONWebKey for _ , key := range downloadedKeys { if key . KeyID == keyID { addingKey = key } if mkc . maxCacheSize == - 1 { mkc . entries [ key . KeyID ] = keyCacherEntry { addedAt : time . Now ( ) , JSONWebKey : key , } } } if addingKey . Key != nil { if mkc . maxCacheSize != - 1 { mkc . entries [ addingKey . KeyID ] = keyCacherEntry { addedAt : time . Now ( ) , JSONWebKey : addingKey , } mkc . handleOverflow ( ) } return & addingKey , nil } return nil , ErrNoKeyFound }
// Add adds a key into the cache and handles overflow
Add adds a key into the cache and handles overflow