Skip to content

LRU 模块Put 方法有 bug #9

@OneHalfTimesFlow

Description

@OneHalfTimesFlow
func (l *LruCache) Put(k, v interface{}) {
	l.lock.Lock()
	defer l.lock.Unlock()
	if l.values.Len() == l.size {
		back := l.values.Back()
		l.values.Remove(back)
		delete(l.cacheMap, back)  // 这里试图删除 back 这个元素。但是通常来说,back 元素本身不会是 map 的 key
	}

	front := l.values.PushFront(v)
	l.cacheMap[k] = front
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions