func (b *LRUCache) removeEntry(e *entry) {
	if e.element.list != &b.lruList {
		panic("list lruList")
	}
	if e.index != -1 {
		heap.Remove(&b.priorityQueue, e.index)
	}
	b.lruList.Remove(&e.element)
	b.freeList.PushElementFront(&e.element)
	delete(b.table, e.key)
	e.key = ""
	e.value = nil
}
Move entry from used/lru list to a free list. Clear the entry as well.
package lrucache
import (
	"container/heap"
	"sync"
	"time"
)
type entry struct {
	element element      
	key     string       
	value   interface{}  
	expire  time.Time    
	index   int          
}
type LRUCache struct {
	lock          sync.Mutex
	table         map[string]*entry  
	priorityQueue priorityQueue      
	lruList       list               
	freeList      list               
	ExpireGracePeriod time.Duration  
}
func (b *LRUCache) Init(capacity uint) {
	b.table = make(map[string]*entry, capacity)
	b.priorityQueue = make([]*entry, 0, capacity)
	b.lruList.Init()
	b.freeList.Init()
	heap.Init(&b.priorityQueue)
	arrayOfEntries := make([]entry, capacity)
	for i := uint(0); i < capacity; i++ {
		e := &arrayOfEntries[i]
		e.element.Value = e
		e.index = -1
		b.freeList.PushElementBack(&e.element)
	}
}
func NewLRUCache(capacity uint) *LRUCache {
	b := &LRUCache{}
	b.Init(capacity)
	return b
}
func (b *LRUCache) expiredEntry(now time.Time) *entry {
	if len(b.priorityQueue) == 0 {
		return nil
	}
	if now.IsZero() {
		now = time.Now()
	}
	if e := b.priorityQueue[0]; e.expire.Before(now) {
		return e
	}
	return nil
}
func (b *LRUCache) leastUsedEntry() *entry {
	return b.lruList.Back().Value.(*entry)
}
func (b *LRUCache) freeSomeEntry(now time.Time) (e *entry, used bool) {
	if b.freeList.Len() > 0 {
		return b.freeList.Front().Value.(*entry), false
	}
	e = b.expiredEntry(now)
	if e != nil {
		return e, true
	}
	if b.lruList.Len() == 0 {
		return nil, false
	}
	return b.leastUsedEntry(), true
}