code: func (serv *v2MetadataService) Add(diffID layer.DiffID, metadata V2Metadata) error {
  	if serv.store == nil {
  		// Support a service which has no backend storage, in this case
  		// an add becomes a no-op.
  		// TODO: implement in memory storage
  		return nil
  	}
  	oldMetadata, err := serv.GetMetadata(diffID)
  	if err != nil {
  		oldMetadata = nil
  	}
  	newMetadata := make([]V2Metadata, 0, len(oldMetadata)+1)
  
  	// Copy all other metadata to new slice
  	for _, oldMeta := range oldMetadata {
  		if oldMeta != metadata {
  			newMetadata = append(newMetadata, oldMeta)
  		}
  	}
  
  	newMetadata = append(newMetadata, metadata)
  
  	if len(newMetadata) > maxMetadata {
  		newMetadata = newMetadata[len(newMetadata)-maxMetadata:]
  	}
  
  	jsonBytes, err := json.Marshal(newMetadata)
  	if err != nil {
  		return err
  	}
  
  	err = serv.store.Set(serv.diffIDNamespace(), serv.diffIDKey(diffID), jsonBytes)
  	if err != nil {
  		return err
  	}
  
  	return serv.store.Set(serv.digestNamespace(), serv.digestKey(metadata.Digest), []byte(diffID))
  }
docs: // Add associates metadata with a layer DiffID. If too many metadata entries are
  // present, the oldest one is dropped.