func (msgCache *MessageCache) Truncate(index int64) {
	for i := len(msgCache.cache) - 1; i >= 0; i-- {
		if (msgCache.cache[i].firstIndex + int64(msgCache.cache[i].cache.GetCount())) > index {
			msgCache.cache = msgCache.cache[:i]
		}
	}
}
/*
Truncate is used to trim the cache in case the underlying commit log has been truncated.
package disklog
import (
	"github.com/owlfish/forestbus-server/model"
)
type CacheEntry struct {
	firstIndex int64
	cache      model.Messages
}
type CacheEntryInfo struct {
	FirstIndex int64
	CacheSize  int
}
type MessageCache struct {
	cache  []*CacheEntry
	hits   int
	misses int
}
type MessageCacheInfo struct {
	CacheSlotsUsed int
	CacheEntryInfo []CacheEntryInfo
	TotalCacheSize int
	Hits           int
	Misses         int
}
func CreateCache(capacity int) *MessageCache {
	msgCache := &MessageCache{}
	msgCache.cache = make([]*CacheEntry, 0, capacity)
	return msgCache
}
func (msgCache *MessageCache) AppendMessages(index int64, msgs model.Messages) {
	if cap(msgCache.cache) == len(msgCache.cache) {
		copy(msgCache.cache, msgCache.cache[1:])
		msgCache.cache = msgCache.cache[:len(msgCache.cache)-1]
	}
	msgCache.cache = append(msgCache.cache, &CacheEntry{firstIndex: index, cache: msgs})
}
func (msgCache *MessageCache) GetMessages(index int64, count int64) model.Messages {
	for _, cacheE := range msgCache.cache {
		maxIndex := cacheE.firstIndex + int64(cacheE.cache.GetCount())
		if index >= cacheE.firstIndex && index < maxIndex {
			localIndex := index - cacheE.firstIndex
			cacheLength := int64(cacheE.cache.GetCount())
			toReturn := cacheLength
			if (toReturn - localIndex) > count {
				toReturn = localIndex + count
			}
			msgCache.hits++
			results, _ := cacheE.cache.Slice(int(localIndex), int(toReturn))
			return results
		}
	}
	msgCache.misses++
	return model.EMPTY_MESSAGES
}