Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 505 Bytes

README.md

File metadata and controls

21 lines (18 loc) · 505 Bytes

Golang LRU Cache

Simple implementation using container/list and map

Example

import github.com/duyquang6/go-lru-cache

func example() {
	cache := lru.NewLRUCache(2)     // initialize new cache with cap = 2
	cache.Put("one", 1)   
	cache.Put("two", 2)
	log.Println(cache.Get("one"))   // return 1
	cache.Put("three", 3)
	log.Println(cache.Get("two"))   // return -1
	cache.Put("four", 4)
	log.Println(cache.Get(1))       // return -1
	log.Println(cache.Get(3))
	log.Println(cache.Get(4))
}