Skip to content

Simple LRU cache using double linked list and hash table

License

Notifications You must be signed in to change notification settings

duyquang6/go-lru-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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))
}

About

Simple LRU cache using double linked list and hash table

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages