code: func (ms *MemoryMsgStore) Store(m *pb.MsgProto) (uint64, error) {
  	ms.Lock()
  	defer ms.Unlock()
  
  	if m.Sequence <= ms.last {
  		// We've already seen this message.
  		return m.Sequence, nil
  	}
  
  	if ms.first == 0 {
  		ms.first = m.Sequence
  	}
  	ms.last = m.Sequence
  	ms.msgs[ms.last] = m
  	ms.totalCount++
  	ms.totalBytes += uint64(m.Size())
  	// If there is an age limit and no timer yet created, do so now
  	if ms.limits.MaxAge > time.Duration(0) && ms.ageTimer == nil {
  		ms.wg.Add(1)
  		ms.ageTimer = time.AfterFunc(ms.limits.MaxAge, ms.expireMsgs)
  	}
  
  	// Check if we need to remove any (but leave at least the last added)
  	maxMsgs := ms.limits.MaxMsgs
  	maxBytes := ms.limits.MaxBytes
  	if maxMsgs > 0 || maxBytes > 0 {
  		for ms.totalCount > 1 &&
  			((maxMsgs > 0 && ms.totalCount > maxMsgs) ||
  				(maxBytes > 0 && (ms.totalBytes > uint64(maxBytes)))) {
  			ms.removeFirstMsg()
  			if !ms.hitLimit {
  				ms.hitLimit = true
  				ms.log.Warnf(droppingMsgsFmt, ms.subject, ms.totalCount, ms.limits.MaxMsgs,
  					util.FriendlyBytes(int64(ms.totalBytes)), util.FriendlyBytes(ms.limits.MaxBytes))
  			}
  		}
  	}
  
  	return ms.last, nil
  }
docs: ////////////////////////////////////////////////////////////////////////////
  // MemoryMsgStore methods
  ////////////////////////////////////////////////////////////////////////////
  // Store a given message.