func (b *LRUCache) GetNotStale(key string) (value interface{}, ok bool) {
	return b.GetNotStaleNow(key, time.Now())
}
GetNotStale gets a key from the cache, make sure it's not stale. Update its
LRU score. O(log(n)) if the item is expired.
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
}
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
}
func (b *LRUCache) insertEntry(e *entry) {
	if e.element.list != &b.freeList {
		panic("list freeList")
	}
	if !e.expire.IsZero() {
		heap.Push(&b.priorityQueue, e)
	}
	b.freeList.Remove(&e.element)
	b.lruList.PushElementFront(&e.element)
	b.table[e.key] = e
}
func (b *LRUCache) touchEntry(e *entry) {
	b.lruList.MoveToFront(&e.element)
}
func (b *LRUCache) SetNow(key string, value interface{}, expire time.Time, now time.Time) {
	b.lock.Lock()
	defer b.lock.Unlock()
	var used bool
	e := b.table[key]
	if e != nil {
		used = true
	} else {
		e, used = b.freeSomeEntry(now)
		if e == nil {
			return
		}
	}
	if used {
		b.removeEntry(e)
	}
	e.key = key
	e.value = value
	e.expire = expire
	b.insertEntry(e)
}
func (b *LRUCache) Set(key string, value interface{}, expire time.Time) {
	b.SetNow(key, value, expire, time.Time{})
}
func (b *LRUCache) Get(key string) (v interface{}, ok bool) {
	b.lock.Lock()
	defer b.lock.Unlock()
	e := b.table[key]
	if e == nil {
		return nil, false
	}
	b.touchEntry(e)
	return e.value, true
}
func (b *LRUCache) GetQuiet(key string) (v interface{}, ok bool) {
	b.lock.Lock()
	defer b.lock.Unlock()
	e := b.table[key]
	if e == nil {
		return nil, false
	}
	return e.value, true
}