func(lru *LRU)Put(key string, val interface{}) { if e, ok := lru.Hash[key]; ok { lru.List.Remove(e) } e := lru.List.PushBack(&Data{Key: key, Val: val}) lru.Hash[key] = e if lru.List.Len() > lru.Cap { f := lru.List.Front() lru.List.Remove(f) delete(lru.Hash, f.Value.(*Data).Key) } }
func(lru *LRU)Get(key string)(val interface{}) { if e, ok := lru.Hash[key]; ok { lru.List.MoveToBack(e) return e.Value.(*Data).Val } returnnil }